Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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 HttpURLConnection POST参数无法正常工作_Android_Https_Http Post - Fatal编程技术网

Android HttpURLConnection POST参数无法正常工作

Android HttpURLConnection POST参数无法正常工作,android,https,http-post,Android,Https,Http Post,我使用POST请求和参数创建了HttpURLConnection以发送到服务器。服务器响应为: 完整性约束冲突:“运算符\u id”列不能为空 但我在查询中清楚地发送了它。我尝试通过终端使用curl,效果很好。服务器接受查询并将其保存到数据库中。我匹配了curl和Android调用中的所有参数值,但没有任何帮助 这是AsyncTask类 public class HttpPost extends AsyncTask<String, String, String> { Contex

我使用POST请求和参数创建了HttpURLConnection以发送到服务器。服务器响应为:

完整性约束冲突:“运算符\u id”列不能为空

但我在查询中清楚地发送了它。我尝试通过终端使用curl,效果很好。服务器接受查询并将其保存到数据库中。我匹配了curl和Android调用中的所有参数值,但没有任何帮助

这是AsyncTask类

public class HttpPost extends AsyncTask<String, String, String> {
  Context context;
  public HttpPost (Context context){
    this.context = context;
  }
   @Override
protected String doInBackground(String... params) {
    URL url;
    String response = "";
    try {
            url = new URL(params[0]);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            String query = "operator_id=1&date=*********";
            conn.setReadTimeout(15000);
            conn.setConnectTimeout(15000);
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("Accept-Charset", "UTF-8");
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);

            OutputStream os = conn.getOutputStream();
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
            writer.write(query);
            writer.flush();
            writer.close();
            os.close();

            int responseCode = conn.getResponseCode();
            .......
            conn.disconnect();
    catch ( Exception e){
      e.printStackTrace();
    }
    return response;
}

有人知道我做错了什么吗?

试着用有效的JSON包装字符串参数应该可以

String query = "{\"operator_id\":1,\"date\":\"*********\"}";

哦,上帝。我认为查询是附加到url。它现在正在工作。谢谢。这有点奇怪,因为你在卷发电话里做得对!
String query = "{\"operator_id\":1,\"date\":\"*********\"}";