Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何在android上发送此类POST请求?_Android_Http_Post - Fatal编程技术网

我如何在android上发送此类POST请求?

我如何在android上发送此类POST请求?,android,http,post,Android,Http,Post,我有这个格式页 <html><head><script> function sendForm(form) { form.value.value = "{ \"y\": " + form.example2.value + " }" form.submit(); } </script></head> <body> <form action="https://....WEBSITE..." metho

我有这个格式页

<html><head><script>
function sendForm(form)
{
      form.value.value = "{ \"y\": " + form.example2.value + " }"
      form.submit();
}
</script></head>
<body>
<form action="https://....WEBSITE..." method="post">
<input type="hidden" name="value">
number:<input type="text" name="example2">
<input type="button" value="Submit" onClick="sendForm(this.form);">
</form>
  </body>
</html>

函数sendForm(form)
{
form.value.value=“{\'y\:“+form.example2.value+”}”
表单提交();
}
编号:
我想知道,如何在android中将其转换为post对象? 我希望从我的android手机发送完全相同的数据
假设我有一个包含我希望发送的整数的变量和表示url的字符串。

使用
StringEntity
类。您可以使用
setEntity()

将StringEntity对象设置为您的
HttpPost

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("value", value));
params.add(new BasicNameValuePair("example2", example2_value));

try {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 10000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);
    HttpClient httpClientpost = new DefaultHttpClient(httpParameters);

    HttpPost post = new HttpPost("https://....WEBSITE...");

    UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);
    post.setEntity(ent);


    HttpResponse responsePOST = httpClientpost.execute(post);
    HttpEntity resEntity = responsePOST.getEntity();
    String getresponse = EntityUtils.toString(resEntity); //Response from the server
} catch (IOException e) {
    e.printStackTrace();
} catch (JSONException e) {
    e.printStackTrace();
}
List params=new ArrayList();
参数添加(新的BasicNameValuePair(“值”,值));
参数添加(新的BasicNameValuePair(“example2”,example2_值));
试一试{
HttpParams httpParameters=新的BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters,10000);
HttpConnectionParams.setSoTimeout(httpParameters,10000);
HttpClient httpClientpost=新的默认HttpClient(httpParameters);
HttpPost=新的HttpPost(“https://....WEBSITE...");
UrlEncodedFormEntity ent=新的UrlEncodedFormEntity(params,HTTP.UTF_8);
邮政实体(ent);
HttpResponse responsePOST=httpClientpost.execute(post);
HttpEntity当前状态=responsePOST.getEntity();
String getresponse=EntityUtils.toString(Recentity);//来自服务器的响应
}捕获(IOE异常){
e、 printStackTrace();
}捕获(JSONException e){
e、 printStackTrace();
}

尝试了一些东西,对吗?我做了一些更改,只使用了1个“参数。添加”和“值”,msg,其中msg是我的变量。当它到达行
HttpResponse responsePOST=httpClientpost.execute(post)
时,它崩溃。有什么原因吗?