Research Development
Research Development

Reputation: 904

java.lang.IllegalArgumentException: in Posting Json data to server Using get Method

11-30 10:34:05.747  21907-21951/info.androidhive.materialdesign E/log_tag﹕ Error in http connection java.lang.IllegalArgumentException: Illegal character in query at index 48:

http://bhaskarmart.com/api/values/savebill?data={userId:2,slotdatetime:21/11/2015%205:00%20PM,address:behind%20behind.%20fhif,total:350,orderdata:[{%22productid%22:%2226%22,%22productcount%22:%221%22}]%20

when I find index at 48 then I found this charcter { so can please tell me how to post Json data I have to Post this data:

{userId:2,slotdatetime:21/11/2015%205:00%20PM,address:behind%20behind.%20fhif,total:350,orderdata:[{"productid":"26","productcount":"1"}]}`

Upvotes: 2

Views: 216

Answers (2)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

Problem is caused by :

response = HttpPost.getJSONfromURL(URLEncoder.encode(totaldata, "UTF-8"));

line because encoding url also with parameters. do it as:

String strUrl="http://bhaskarmart.com/api/values/savebill?data=";
String strJson="{"+ finalOrderdata +"}";
response = HttpPost.getJSONfromURL(strUrl+URLEncoder.encode(strJson, "UTF-8"));

Upvotes: 0

Chirag Savsani
Chirag Savsani

Reputation: 6140

Your JSON data is not valid.

Below is valid JSON data.

Add double quote in Json key.

{
    "userId": 2,
    "slotdatetime": "21/11/2015%205:00%20PM",
    "address": "behind%20behind.%20fhif",
    "total": 350,
    "orderdata": [
        {
            "productid": "26",
            "productcount": "1"
        }
    ]
}

Upvotes: 1

Related Questions