我需要我的程序向服务器发送请求。问题是,服务器只识别 ös、äs 和 üs,但 JAVA 和/或 Android 不知道它们。 `如何在不使用 JAVA/Android“更改”ö 的情况下使用“Hermann-Löns”之类的字符串发送请求……哦,顺便说一句,服务器也无法识别“oe”,已经尝试过了。 ..
谢谢你的帮助!
@BalausC:
我将您的代码更改为:
我不确定这是否是您引用正确字段的方式...
String url = "http://busspur02.aseag.de/bs.exe?SID=473A2&ScreenX=1440&ScreenY=900&CMD=CR&DatumT=30&DatumM=4&DatumJ=2010&AbfAnk=Abf&ZeitH=10&ZeitM=45&Intervall=60&Loeschen=%28N%29eue+Suche";
String charset = "CP1252";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("HTO", start_from));
params.add(new BasicNameValuePair("HT1", destination));
UrlEncodedFormEntity query = new UrlEncodedFormEntity(params, charset);
HttpPost post = new HttpPost(url);
post.setEntity(query);
InputStream response = new DefaultHttpClient().execute(post).getContent();
// Now do your thing with the facebook response.
我无法编译,因为我收到一条错误消息:
The method getContent() is undefined for the type HttpResponse
如果我删除 getContent() 是说:
Type mismatch: cannot convert from HttpResponse to InputStream
还有一件事:我使用 htmlparser ( http://htmlparser.sourceforge.net/ ) 来解析生成的网站。我如何访问生成的 html 站点来解析它?因为否则我将不得不重写几乎所有代码才能获得结果..
最佳答案
至此,您需要使用具有适当字符编码的 java.net.URLEncoder
来对请求参数中的特殊字符进行编码。
String param = URLEncoder.encode("Hermann-Löns", "CP1252");
确保您在 HTTP 请求中指定了 Accept-Charset: CP1252
header 。有关如何使用正确编码触发 HTTP 请求的更完整代码示例,请查看 this answer我一小时前发布的。它还涵盖了一个 HttpClient 示例,该示例也包含在 Android 中。
关于java - 我需要在我的程序中使用 "ö","ä"."ü",但是 java/android 不允许我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2739447/