- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,我是 StackOverFlow 的新人
实际上我正在尝试从官方数据库( https://emf2.bundesnetzagentur.de/karte/Default.aspx )获取数据。我使用java并尝试通过带有参数的post请求获取信息。我编写了两个不同的版本,一种使用 Apache httpclient,另一种使用 java.net。我还有一个用 Python 编写的版本(不是我的)
java中的不行!我至少收到此错误作为响应:
Statuscode: 500 Internal Server Error
{"d":{"Message":"Fehler bei der Suche nach Funkanlagenstandorten.","StackTrace":"","Source":"","InnerException":""}}
System.InvalidOperationException: 'GetStandorteFreigabe' ist kein gültiger Webdienst-Methodenname. bei System.Web.Services.Protocols.HttpServerProtocol.Initialize() bei System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.simple.JSONObject;
import objects.BoundingBox;
import objects.Header;
public class HttpClientTest
{
// TODO Größe der Bounding Box?
public static void main(String[] args)
{
try
{
new HttpClientTest();
}
catch (IOException e)
{
e.printStackTrace();
}
}
Header header;
@SuppressWarnings("unchecked")
public HttpClientTest() throws ClientProtocolException, IOException
{
List<BoundingBox> boxes = getBboxes();
for (BoundingBox bBox : boxes)
{
HttpClient client = null;
CookieStore cookieStore = new BasicCookieStore();
HttpClientBuilder builder = HttpClientBuilder.create().setDefaultCookieStore(cookieStore);
client = builder.build();
String cookie = getCookie();
HttpPost postRequest = new HttpPost(
"https://" + Start.EMF + ".bundesnetzagentur.de/karte/Standortservice.asmx/GetStandorteFreigabe");
header = new Header().getDefaultHeader();
header.add("Cookie", cookie);
Set<String> entries = header.keySet();
for (String key : entries)
postRequest.addHeader(key, header.get(key));
// Request parameters and other properties.
JSONObject obj = new JSONObject();
JSONObject subObj = new JSONObject();
subObj.put("sued", bBox.getSouth());
subObj.put("west", bBox.getWest());
subObj.put("nord", bBox.getNorth());
subObj.put("ost", bBox.getEast());
obj.put("Box", subObj);
System.out.println("RequestJSON: " + obj.toJSONString());
StringEntity requestEntity = new StringEntity(obj.toJSONString());
requestEntity.setContentEncoding("UTF-8");
requestEntity.setContentType("application/json");
postRequest.setEntity(requestEntity);
// Execute and get the response.
HttpResponse response = client.execute(postRequest);
System.out.println(response.getStatusLine());
System.out.println(Arrays.deepToString(response.getAllHeaders()));
HttpEntity entity = response.getEntity();
if (entity != null)
{
StringBuilder sb = new StringBuilder();
try (InputStream instream = entity.getContent())
{
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
for (String line; (line = reader.readLine()) != null;)
{
sb.append(line + "\r\n");
}
reader.close();
// do something useful
}
System.out.println(sb.toString());
}
}
}
private String getCookie()
{
StringBuilder cookieStringBuilder = new StringBuilder();
try
{
HttpClient client = null;
CookieStore cookieStore = new BasicCookieStore();
HttpClientBuilder builder = HttpClientBuilder.create().setDefaultCookieStore(cookieStore);
client = builder.build();
HttpGet httpGet = new HttpGet("https://" + Start.EMF + ".bundesnetzagentur.de/karte/Default.aspx");
client.execute(httpGet);
cookieStore.getCookies().forEach(e ->
{
cookieStringBuilder.append(e.getName() + " = " + e.getValue());
cookieStringBuilder.append(";");
});
}
catch (IOException e1)
{
e1.printStackTrace();
}
System.out.println("Cookie: " + cookieStringBuilder.toString());
return cookieStringBuilder.toString();
}
private List<BoundingBox> getBboxes()
{
// BoundingBox box = new BoundingBox();
BoundingBox box = new BoundingBox(13.679351806640627, 51.06313741319562, 13.723812103271484,
51.082174834773625);
List<BoundingBox> bBoxes = new ArrayList<>();
bBoxes.add(box);
// double south, west, north, east;
// south = box.getSouth();
//
// while (south <= box.getNorth())
// {
// north = south + JavaDefaultTest.STEP;
// west = box.getWest();
// while (west <= box.getEast())
// {
// east = west + JavaDefaultTest.STEP;
// bBoxes.add(new BoundingBox(west, south, east, north));
// west += JavaDefaultTest.STEP;
// }
// south += JavaDefaultTest.STEP;
// }
return bBoxes;
}
}
边界框:
package objects;
import java.util.ArrayList;
import java.util.List;
/**
* order: west, south, east, north
*
* @author Zinke
*
*/
public class BoundingBox
{
public final static double STEP = 0.03d;
private double north;
private double east;
private double west;
private double south;
private static final double northMin = 47.0f, northMax = 55.0f;
private static final double eastMin = 5.0f, eastMax = 16.0f;
/**
* <b>Initial constructor</b><br>
* <br>
* Bounding box for data scraping: Germany<br>
* coordiantes in decimal degree<br>
* <br>
* order: west, south, east, north
*/
public BoundingBox()
{
setWest(eastMin);
setSouth(northMin);
setEast(eastMin + STEP);
setNorth(northMin + STEP);
}
/**
* Bounding box for data scraping: Germany<br>
* coordiantes in decimal degree<br>
* order: west, south, east, north
*
* @param west
* @param south
* @param east
* @param north
*/
public BoundingBox(double north, double east,double south,double west)
{
setWest(west);
setNorth(north);
setEast(east);
setSouth(south);
}
public double getNorth()
{
return north;
}
public void setNorth(double north)
{
this.north = north;
}
public double getEast()
{
return east;
}
public void setEast(double east)
{
this.east = east;
}
public double getWest()
{
return west;
}
public void setWest(double west)
{
this.west = west;
}
public double getSouth()
{
return south;
}
public void setSouth(double south)
{
this.south = south;
}
/**
* Returns a list with bounding boxes for whole germany <br>
* From Southest+Westest Point beginning
*
* @return
*/
public static List<BoundingBox> getAllBboxes()
{
BoundingBox box = new BoundingBox();
List<BoundingBox> bBoxes = new ArrayList<>();
bBoxes.add(box);// set Starting Box
double south, west, north, east;
south = box.getSouth();
while (south <= northMax)
{
north = south + BoundingBox.STEP;
west = box.getWest();
while (west <= eastMax)
{
east = west + BoundingBox.STEP;
bBoxes.add(new BoundingBox(north,east,south,west));
west += BoundingBox.STEP;
}
south += BoundingBox.STEP;
}
return bBoxes;
}
}
有人可以帮我吗?
最佳答案
你的代码似乎可以工作。我刚刚尝试过,仅更改了示例中提供的坐标值,并从我的浏览器调试控制台中提取了一些坐标值,并且它有效:
{"nord":51.7151177895987,"ost":12.70294189453125,"sued":9.857482910156252,"west":50.49770501038011}
我的猜测是,您应该确保您的 BoundingBox
类中没有错误,并且每个坐标值的范围是合适的。
关于java - 为什么我使用 java post-request 来响应状态代码 500 的内部服务器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58373814/
这两个句子有什么区别: res = requests.request('POST', url) 和 res = requests.request.post(url) 最佳答案 它们几乎是一样的:htt
我正在使用“请求对话框”来创建 Facebook 请求。为了让用户收到请求,我需要使用图形 API 访问 Request 对象。我已经尝试了大多数看起来合适的权限设置(read_requests 和
urllib.request和http.client都是python标准库。前者相关方法的文档是 here后者,here (我使用的是3.5) 有谁知道为什么标准库中有两种方法看起来做同样的事情,或者
我是 Twisted 的新手,我不明白为什么在运行我的脚本时会出现此错误。\ 基本上,该脚本由 2 个页面组成,第一个页面是一个 HTML 表单,它调用自身执行一个阻塞方法并显示结果。当请求同时发送到
我有一个客户端 JS 文件,其中包含: agent = require('superagent'); request = agent.get(url); 然后我有类似的东西 request.get(u
提前输入功能可以正常工作。但问题是,提前输入功能会在每个数据请求上发出 JSON 请求,而实际上只应针对一个特定请求发生。 我有以下 Controller : #controllers/agencie
我正在使用 Rust 开发一个小型 API,我不确定如何在两个地方访问来自 Iron 的 Request。 Authentication 中间件为 token 读取一次Request,如果路径被允许(
问题起因 今天一位网友向我们反馈,用Chrome打开某些博客文章时,会出现"Bad Request - Request Too Long. HTTP Error 400. The siz
当我从 LinkedIn 向 https://api.linkedin.com/uas/oauth/requestToken 请求请求 token 时,出现以下错误: oauth_problem=si
我只是想使用 okhttp 下载一些字节数据,但在我完成代码之前,我遇到了一个问题,android studio 报告了一个错误,说“Request(okhttp3.Request.Builder)
我正在使用 Windows 10。我想在我的系统上使用 Angular 4。当我运行 node -v 和 npm -v 时,它会显示版本。但是当我执行语句 npm install -g @angula
我正在尝试让一个简单的 Iron 示例起作用: extern crate iron; extern crate router; use iron::prelude::*; use iron::stat
我正在尝试使用嵌套字典“动态”创建一个数据输入表单(目前,我使用具有 3 个值的数组,但将来数组中的元素数量可能会有所不同)。这似乎工作正常,并且表单“正确”渲染了 html 模板(正确 = 我看到了
从 ASP.NET 中的代码隐藏访问表单或查询字符串值时,使用的优缺点是什么,例如: // short way string p = Request["param"]; 代替: // long way
我遇到了一个问题,我想知道更好的解决方法。 有五个 api 请求并行运行,第二个请求依赖于第四个请求的响应,但所有 5 个请求都已在运行。什么是更好的方法? 需要建议。提前致谢。 最佳答案 调度地面工
我收到以下错误:TypeError:序列项 0:预期字节、字节数组或具有缓冲区接口(interface)的对象、找到元组 我检查了Python文档,urllib.request.Request的参数似
当我向函数添加超时参数时,我的代码总是进入异常并打印出“我失败了”。当我删除超时参数时,代码会正常工作,并进入 try 子句。关于超时参数如何在 urllib.request 函数中工作的任何信息?
我使用 cURL 向服务器发送请求这是链接:Server Side script for cURL request我用 file_get_contents('php://input'); 读取发送的数
请大家帮帮我我正在尝试使用 NUTCH 抓取网站,但它给我错误“java.io.IOException: Job failed!” 我正在运行此命令“bin/nutch solrindex http:
在我的 AngularJS 应用程序中,我无法弄清楚如何对 then promise 的执行更改 location.url 进行单元测试。我有一个函数,登录 ,调用服务,身份验证服务 .它返回 pro
我是一名优秀的程序员,十分优秀!