【发布时间】:2015-08-11 07:16:11
【问题描述】:
我正在尝试从两个 EditText-views 发送 JSON 格式数据(使用 Volley)和一个从我的 Android 应用程序返回唯一设备 ID 到 URL 的方法,我收到 "[8970] BasicNetwork.performRequest:https://gorountsiallyetlasornall:5wxGq5UNlY6wdWmNAyYPVVrN@bulberadev.cloudant.com/notebook 的意外响应代码 401"
这是我的方法:
private void doPost() {
final String url = "https://gorountsiallyetlasornall:5wxGq5UNlY6wdWmNAyYPVVrN@bulberadev.cloudant.com/notebook";
final String deviceId = getDeviceId(getApplicationContext());
try {
try {
JSONObject jsonObject = new JSONObject();
String title = editTitle.getText().toString();
String content = editContent.getText().toString();
jsonObject.put("title", title);
jsonObject.put("content", content);
jsonObject.put("deviceId", "<" + deviceId + ">");
} catch (JSONException e) {
e.printStackTrace();
}
requestQueue = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
url, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Log.e("VOLLEY", "ERROR");
}
});
requestQueue.add(jsonObjectRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
它应该采用以下格式:
{
"title":"Birth day",
"content":"Buy a gift for my mom!",
"deviceId":"<Device ID>"
}
【问题讨论】:
-
我认为这与 SSL ..
标签: android http post android-volley