I have code to Post data in server ,
this is my code
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("phone", mPhoneNumber));
params.add(new BasicNameValuePair("prod_title", nama));
params.add(new BasicNameValuePair("prod_desc", des));
JSONObject json = jsonParser.makeHttpRequest(Constants.url_create_product, "POST", params);
// check log cat from response
Log.d("Create Response", json.toString());
try {
int success = json.getInt(Constants.TAG_SUCCESS);
if (success == 1) {
// successfully created user
Intent i = new Intent(getApplicationContext(), shoop3Activity.class);
i.putExtra("phone", mPhoneNumber);
startActivity(i);
// closing this screen
finish();
} else {
// failed to create user
Toast.makeText(getApplicationContext(),"Gagal bikin user", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
but it show error like this
10-08 12:36:11.857: INFO/ActivityManager(59): Displayed activity shoop3.android.edu/.Activity3: 1074 ms (total 1074 ms)
10-08 12:36:16.037: ERROR/JSON Parser(881): Error parsing data org.json.JSONException: Value <div of type java.lang.String cannot be converted to JSONObject
10-08 12:36:16.037: DEBUG/Create Response(881): {"status":1}
10-08 12:36:16.127: INFO/ActivityManager(59): Starting activity: Intent { cmp=shoop3.android.edu/.setupstoreActivity (has extras) }
10-08 12:36:17.507: INFO/ActivityManager(59): Displayed activity shoop3.android.edu/.setupstoreActivity: 1191 ms (total 1191 ms)
any solution pleasee?? it show error parsing data … string cannot be converted to JSonObject
The server is responding with HTML data and you are trying to parse it as JSON data. This won’t work. You should check what exactly are the parameters you’re passing to the server and test this in a browser. Perhaps you need to be logged in/authenticated but you aren’t passing the cookies up or something?