Android Question HTTPUtils2 POST formatting

ihatton

Member
Licensed User
Longtime User
I am trying to use HTTPUtils2 to POST data to an IoT server which needs to be received in the following format:

"content": {
"temp": "Hello World "
}

When I use my code below, I get the following format which is close but not correct. Any ideas as to what code change is required in order to get the correct format? I tried using the JSONGenerator to see if that worked but the resulting data format was even further from the required format :-(

"content": {
"temp:Hello World": ""
}

Current Code:

msg=nfctag.Text
msg= msg.Replace ( " ","%20")
msg= "temp:"&msg
job1.PostString("https://dweet.io:443/dweet/for/test?key=xxxxxxxxxxxxxxxxxxx",msg)
 

ihatton

Member
Licensed User
Longtime User


Thanks for the tip - I tried that but the received data is still not formatted correctly:

{
"{\"temp\":\"Tag Data goes here\"}": ""
}

Is there any way to check the raw data being sent via PostString without using a network sniffer? The spec for the IoT server update is as follows and I need to check where the data sent from my app differs from this spec. I am also wondering if I need to set the content type to "application/json" and if there is a way to do this for POST with the current Httputils2?

{
"path" : "/dweet/for/{thing}",
"operations": [
{
"method" : "POST",
"nickname" : "postDweet",
"parameters" : [
{
"paramType" : "path",
"name" : "thing",
"description": "A unique name of a thing. It is recommended that you use a GUID as to avoid name collisions.",
"dataType" : "string",
"required" : true
},
{
"paramType" : "query",
"name" : "key",
"description": "A valid key for a locked thing. If the thing is not locked, this can be ignored.",
"dataType" : "string",
"required" : false
},
{
"paramType" : "body",
"name" : "content",
"description": "The actual content of the string. Can be any valid JSON string.",
"dataType" : "string",
"required" : true
}
],
"summary" : "Create a dweet for a thing.",
"errorResponses": []
}
]
}
 
Upvote 0

ihatton

Member
Licensed User
Longtime User
I found that the code which works with a locked dweet.io thing is not JSON formatted and is actually very simple i.e.

' replace spaces with %20
msg= msg.Replace ( " ","%20")
job1.PostString("https://dweet.io:443/dweet/for/test?key=xxxxxxxxxxxxxxxx","temp="&msg)

It was just a matter of getting the format right (using = instead of : ) for the update to work correctly but thanks for the help with this.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…