2
A
回答
4
你可以不喜欢它:
Http Post:
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://blahblah.blah/index.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("command", "make"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
HTTP GET
HttpResponse response = null;
try {
// Create http client object to send request to server
HttpClient client = new DefaultHttpClient();
// Create URL string
String URL = "http://blahblah.blah/index.php?command=make";
// Create Request to server and get response
HttpGet httpget= new HttpGet();
httpget.setURI(new URI(URL));
response = client.execute(httpget);
} catch (URISyntaxException e) {
e.printStackTrace();
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
1
你可以简单地通过设置URL是,当你使用URL连接
// you can pass mUrl as http://blahblah.blah/index.php?command=make and if you are expecting a returned value, you can compare that with successVal
public static boolean checkSuccess(String mUrl, String successVal)
{
InputStream is = null;
try
{
URL url = new URL(mUrl);
URLConnection ucon = url.openConnection();
ucon.setConnectTimeout(5000);
ucon.setReadTimeout(5000);
is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 8192);
ByteArrayBuffer baf = new ByteArrayBuffer(300);
int current = 0;
while ((current = bis.read()) != -1)
{
baf.append((byte) current);
}
String success = new String(baf.toByteArray());
return success.equals(successVal);
}
catch (Exception e)
{
return false;
}
finally
{
try
{
if (is != null)
{
is.close();
}
}
catch (Exception e)
{
}
}
}
相关问题
- 1. 如何使用Jquery发送GET请求?
- 2. 如何使用Java发送GET请求
- 3. 如何使用Firebase和Angular发送HTTP GET请求?
- 4. 如何使用Telnet发送HTTP请求
- 5. C:发送HTTP GET请求在linux
- 6. 发送多个异步HTTP GET请求
- 7. C#clickatell发送短信HTTP GET请求
- 8. 如何用PHP curl发送GET请求
- 9. 如何在img标签的onerror属性上发送http请求?
- 10. 使用Titanium.Network.createHTTPClient()发出HTTP-GET请求
- 11. 如何使用HTTP GET请求
- 12. 使用用户名/密码发送GET HTTP请求的XMLHttpRequest
- 13. 使用HTTP GET请求angularjs
- 14. 如何用PyQt发送http请求?
- 15. 发送HTTP请求
- 16. 发送HTTP请求
- 17. 无法使用python发送GET请求
- 18. Node.js - 使用请求在for循环中发送多个HTTP GET
- 19. 使用AngularJS向KDB +进程发送HTTP GET请求
- 20. 无法使用scapy和scapy ssl库发送HTTP/2 GET请求
- 21. 在Windows中使用C发送HTTP GET或POST请求
- 22. LUA - 使用HTTP GET请求发送数据到PHP
- 23. 使用Ethercard库发送带请求标头的HTTP GET
- 24. 使用电报机器人发送HTTP GET请求的结果
- 25. 如何发送HTTP GET请求到代理与Android
- 26. 如何在C#中的HTTP GET请求后发送FIN + ACK?
- 27. 用swift发送http请求
- 28. 如何在html中发送GET请求
- 29. 如何通过Django发送GET请求
- 30. 如何发送https GET请求与oauth
这是一个HTTP POST做到这一点。问题是我的答案更新了HTTP GET –
。 –
我用你的get方法和我的应用程序崩溃,每次我按下按钮 –