我对PHP,JavaScript和许多其他脚本语言很有经验,但我没有很多Java或Android的经验.
我正在寻找一种方法将POST数据发送到PHP脚本并显示结果.
我正在使用我正在使用的库的问题.它可能是图书馆,也可能是我使用它错了!
基本上,当我这样做时(以毫秒为单位的超时)
_ignitedHttp.setConnectionTimeout(1); // v short
_ignitedHttp.setSocketTimeout(60000); // 60 seconds
Run Code Online (Sandbox Code Playgroud)
没有生成超时异常并且它正常工作,但是,当我执行以下操作时,
_ignitedHttp.setConnectionTimeout(60000); // 60 seconds
_ignitedHttp.setSocketTimeout(1); // v short
Run Code Online (Sandbox Code Playgroud)
我得到一个Socket Exception.
所以,我的问题是为什么我不能模拟连接异常?我是否误解了套接字和连接超时之间的区别?图书馆在这里(尚未正式发布).
我在localhost中创建了一个php脚本,我正在连接它,httpClient但是我遇到了问题.
请告诉我如何从模拟器连接到localhost的php文件?
三者之间有什么区别(标记为评论):
MultiThreadedHttpConnectionManager connManag = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managParams = connManag.getParams();
managParams.setConnectionTimeout(connectiontimeout); // 1
managParams.setSoTimeout(sotimeout); //2
HttpMethodBase baseMethod = null;
try {
HttpClient client = new HttpClient(connManag);
client.getParams().setParameter("http.connection-manager.timeout", poolTimeout); //3
baseMethod = new GetMethod(…);
int statusCode = client.executeMethod(…);
…
}
catch (ConnectTimeoutException cte ){
//Took too long to connect to remote host
}
catch (SocketTimeoutException ste){
//Remote host didn’t respond in time
}
catch (Exception se){
//Some other error occurred
}
finally {
if (baseMethod != null)
baseMethod.releaseConnection();
}
Run Code Online (Sandbox Code Playgroud)
1. setConnectionTimeout …
我想向需要身份验证的服务器生成POST请求.我试着使用以下方法:
private synchronized String CreateNewProductPOST (String urlString, String encodedString, String title, String content, Double price, String tags) {
String data = "product[title]=" + URLEncoder.encode(title) +
"&product[content]=" + URLEncoder.encode(content) +
"&product[price]=" + URLEncoder.encode(price.toString()) +
"&tags=" + tags;
try {
URL url = new URL(urlString);
URLConnection conn;
conn = url.openConnection();
conn.setRequestProperty ("Authorization", "Basic " + encodedString);
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != …Run Code Online (Sandbox Code Playgroud) 当我尝试打开一个用jsoup解析的链接时,我收到一个错误.
连接命令:
Document doc = Jsoup.connect("http://www.rfi.ro/podcast/emisiune/174/feed.xml")
.timeout(10 * 1000).get();
Run Code Online (Sandbox Code Playgroud)
抛出的错误:
Exception in thread "main" org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml. Mimetype=application/rss+xml; charset=utf-8, URL=http://www.rfi.ro/podcast/emisiune/174/feed.xml
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:453)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
at podcast.Pods.main(Pods.java:41)
Run Code Online (Sandbox Code Playgroud) 我正在使用Apache HTTP Client开发Java .
使用Java,我如何测试URL是否可联系,并返回有效的响应?
http://stackoverflow.com/about
Run Code Online (Sandbox Code Playgroud) 由于各种原因,我需要runOnUiThread()实际的WebView实例化和初始化.
这意味着它的底层HTTP连接也是在UI线程上进行的?
如果这是真的,是否可以将WebView的UI thead与HTTP连接线程分开?
如果有可能,实现这一目标的正确方法是什么?
android httpconnection android-networking android-webview android-asynctask
此问题是Max HTTP Connections的扩展
Web工作者给这个等式带来了什么样的影响,限制会增加吗?如同3个网络工作者能够发送(3*浏览器限制)请求?
httpconnection ×10
java ×7
android ×3
html5 ×1
http ×1
httpclient ×1
jsoup ×1
localhost ×1
php ×1
pooling ×1
post ×1
tcp ×1
url ×1
web-worker ×1