I am doing an update on the old project & I don't have much knowledge of Android as of now. In project we have Comments section on product.
我正在更新旧的项目&到目前为止我还不太了解Android。在项目中,我们有关于产品的评论部分。
For comment after sending earlier we had return as 0 (some error) & 1 (success).
在发送之前,我们返回的是0(一些错误)和1(成功)。
Below is the code we were using.
下面是我们正在使用的代码。
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Method.POST,
act.getString(R.string.CommentForUserURL),
null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(
JSONObject response) {
Log.d("response done", "done===" + response);
mloading.setVisibility(View.GONE);
if (response != null) {
Comment obj = new Comment();
JSONObject jsonObject = response;
try {
obj.setComment(jsonObject
.getString("Comment"));
Now we have changed the return object from 0/1 to user object.
现在我们已经将返回对象从0/1更改为user对象。
Does this need need to update JsonObjectRequest to GJSON request? Or object will also get parsed with JsonObjectRequest?
是否需要更新JsonObjectRequest到GJSON请求?或者对象也会被JsonObjectRequest解析?
I am asking because when I execute above, I get error as below.
我这样问是因为当我执行上面的操作时,会得到下面的错误。
01-25 12:30:21.754: E/Volley(16487): [10114] BasicNetwork.performRequest:
Unexpected response code 500 for
http://new.souqalharim.com/add/CommentForMerchant
Any idea why I am getting this error?
知道我为什么会犯这个错误吗?
Note: This URL is working fine for iPhone application.
注意:这个URL在iPhone应用程序中运行良好。
Edit 1
This is post method, so full url is not there. There are few more parameters to add like ?comment=MyComment&userId=123&productId=234. As it is post I am not adding parameters in actual url.
这是post方法,所以没有完整的url。还有一些参数需要添加,比如?comment= commentmy&userid =123&productId=234。因为它是发布的,所以我没有在实际的url中添加参数。
I have those in another methods
我用另一种方法
@Override
protected Map<String, String> getParams()
throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("productId", productId.toString());
params.put("userId",
mSessionManager.getUserCode().toString());
params.put("comment", GlobalFunctions
.EncodeParameter(med_comments
.getText().toString()));
return params;
}
Full url is as below.
完整url如下所示。
http://new.souqalharim.com/add/CommentForUser?productId=325&userId=5&comment=abcd
http://new.souqalharim.com/add/CommentForUser?productId=325&userId=5&comment=abcd
I tested this in Mozilla RESTClient and it works fine.
我在Mozilla RESTClient中测试过,它工作得很好。
Edit 2
After checking further I found protected Map<String, String> getParams() throws AuthFailureError {
is not getting called. Any idea why this is happening?
在进一步检查之后,我发现保护映射
3 个解决方案
#1
9
The problem is below.
下面的问题是。
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Method.POST,
act.getString(R.string.CommentForUserURL),
null, new Response.Listener<JSONObject>() {
^^^^
It should be
它应该是
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Method.POST,
act.getString(R.string.CommentForUserURL),
new JSONObject(params), new Response.Listener<JSONObject>() {
^^^^^^^^^^^^^^^^^^^^^^
Copy code from protected Map<String, String> getParams()
before final JsonObjectRequest
.
从受保护的映射
That's it!!!
就是这样! ! !
Reason is as below.
原因是如下。
The JsonObjectRequest is extended JsonRequest which override getBody()
method directly, so your getParam() would never invoke, I recommend you extend StringRequest instead of JsonObjectRequest.
JsonObjectRequest是一个扩展的JsonRequest,它直接覆盖getBody()方法,因此您的getParam()不会调用,我建议您将StringRequest扩展而不是JsonObjectRequest。
your can check this answer for more details.
你可以查看这个答案以获得更多的细节。
#2
0
Try to change php
file permission to 755
.
尝试将php文件权限更改为755。
#3
0
Actually 500 means Internal server error and this is caused by the Rest-api you are calling and not due to Volley,so check the back-end code.
实际上500表示内部服务器错误,这是由您正在调用的Rest-api引起的,而不是由于截击,所以请检查后端代码。
#1
9
The problem is below.
下面的问题是。
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Method.POST,
act.getString(R.string.CommentForUserURL),
null, new Response.Listener<JSONObject>() {
^^^^
It should be
它应该是
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Method.POST,
act.getString(R.string.CommentForUserURL),
new JSONObject(params), new Response.Listener<JSONObject>() {
^^^^^^^^^^^^^^^^^^^^^^
Copy code from protected Map<String, String> getParams()
before final JsonObjectRequest
.
从受保护的映射
That's it!!!
就是这样! ! !
Reason is as below.
原因是如下。
The JsonObjectRequest is extended JsonRequest which override getBody()
method directly, so your getParam() would never invoke, I recommend you extend StringRequest instead of JsonObjectRequest.
JsonObjectRequest是一个扩展的JsonRequest,它直接覆盖getBody()方法,因此您的getParam()不会调用,我建议您将StringRequest扩展而不是JsonObjectRequest。
your can check this answer for more details.
你可以查看这个答案以获得更多的细节。
#2
0
Try to change php
file permission to 755
.
尝试将php文件权限更改为755。
#3
0
Actually 500 means Internal server error and this is caused by the Rest-api you are calling and not due to Volley,so check the back-end code.
实际上500表示内部服务器错误,这是由您正在调用的Rest-api引起的,而不是由于截击,所以请检查后端代码。