Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.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
Java 尝试将post数据发送到nodejs服务器_Java_Node.js_Json - Fatal编程技术网

Java 尝试将post数据发送到nodejs服务器

Java 尝试将post数据发送到nodejs服务器,java,node.js,json,Java,Node.js,Json,这是我在一个问题上坚持了几天。我必须向服务器发送包含json数据的post请求,我尝试以下方法: private void sendRequestInfo() { JSONObject json = new JSONObject(); try { json.put("email", "test@gmail.com"); json.put("password", "abcd"); } catch (JSONException e) {

这是我在一个问题上坚持了几天。我必须向服务器发送包含json数据的post请求,我尝试以下方法:

 private void sendRequestInfo() {

    JSONObject json = new JSONObject();
    try {
        json.put("email", "test@gmail.com");
        json.put("password", "abcd");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    mRequestQueue = Volley.newRequestQueue(this);
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, json,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    resultOne.setText(response.toString());
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            resultOne.setText(error.toString());
        }
    });

    mRequestQueue.add(jsonObjectRequest);

}
private void sendRequestInfo(){
JSONObject json=新的JSONObject();
试一试{
json.put(“电子邮件”test@gmail.com");
put(“密码”、“abcd”);
}捕获(JSONException e){
e、 printStackTrace();
}
mRequestQueue=Volley.newRequestQueue(this);
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Request.Method.POST,url,json,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
resultOne.setText(response.toString());
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
resultOne.setText(error.toString());
}
});
添加(jsonObjectRequest);
}
与服务器的通信似乎已完成,因为node显示以下行:

执行(默认):选择
id
username
password
services
createdAt
updatedAt
FROM
users
AS
users
其中
users
用户名
='register@gmail.com"限额1,

但我有一个错误:

“无法将java.lang.String类型的记录值转换为JSONObject”


通常情况下,如果有人可以帮助我,节点服务器应该将“用户未找到”返回给我。我不理解此错误

您是否错过了POSTMan中的标题内容类型或任何身份验证?此命令有效:curl--header“Content-Type:application/json”-X POST--data'{“email”:test@gmail.com“,”密码“:“abcd”}”,如何在代码中添加“内容类型”?您必须在代码中写入。。。。。。。。。。。问题不在于服务器,而在于我的应用程序中的java代码:/POSTMan中是否缺少标题内容类型或任何身份验证?此命令有效:curl--header“Content-Type:application/json”-X POST--data'{“email”:test@gmail.com,“密码”:“abcd”},如何在代码中添加“内容类型”?您必须在代码中写入。。。。。。。。。。。问题不在于服务器,而在于我的应用程序中的java代码:/