我试图得到像
StringEntity entity;
private static final int TIMEOUT_MILLISEC = 20000;
private static final String serverurl = "http://appcodetechnology.net/meravenue/api/";
下面的函数 m 调用
post("master_details.php");
//
public String post(String request)
{
String result = null;
try
{
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params,TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(params,TIMEOUT_MILLISEC);
HttpClient client = new DefaultHttpClient(params);
System.out.println("Getting url: "+request);
HttpPost post = new HttpPost(serverurl+request);
String body = "{\"action\":\"get_all_cities\"}";
try {
//entity = new StringEntity("action=" + java.net.URLEncoder.encode(body, "utf-8"));
//entity = new StringEntity("data=" + java.net.URLEncoder.encode(body, "utf-8"));
entity = new StringEntity(java.net.URLEncoder.encode(body, "utf-8"));
entity.setContentType("application/x-www-form-urlencoded");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// entity.setContentType("application/x-www-form-urlencoded");
post.setEntity(entity);
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
if(entity != null)
{
result = EntityUtils.toString(entity);
}
else
{
Log.d("Response Failed","Response from server is failed");
}
}catch(Exception ex)
{
ex.printStackTrace();
}
return result;
}
并得到回应
{"result":false,"message":"Invalid method name.","error_code":"406"}
我没有任何错误。
对于以下 API 我正在工作
URL : http://appcodetechnology.net/meravenue/api/master_details.php
Method : POST
Request Body : {"action":"get_all_cities"}
但没有得到回应