Android Question POSTing a JSON object with HttpUtils2

pjetson

Member
Licensed User
Longtime User
I need to change the content type to "application/json", and I've found a couple of discussions in the forums, but none of them seem to explain how to do it.

One poster says that "I have modified the HttpJob module with: req.SetContentType ( "application/json")". Where is this HttpJob module, and how do I modify it?

In another post, Erel says:
You can modify this sub:
Public Sub GetRequest As HttpRequest
Return req
End Sub
And add:
req.SetContentType(...)

But where is this GetRequest sub located? And, again, how do I modify it?

In that same thread, another poster says that he has this in his code:

job2.PutString("http://10.0.1.54:8080/security/register", objJSon.ToPrettyString(2))
job2.GetRequest.SetContentType("application/json")

However, when I try this, the compiler says:

Error description: Unknown type: anywheresoftware.b4a.http.HttpClientWrapper.HttpUriRequestWrapper
Are you missing a library reference?
Occurred on line: 211
job2.GetRequest.SetContentType("application/json")
Word: setcontenttype

Help!

Can someone please explain exactly what I need to do, and where and how to do it?

Thanks, Peter
 

sorex

Expert
Licensed User
Longtime User
do you really need that to post a json "block" ?

it's plain text so I would expect it to work with a regular post.
 
Upvote 0

pjetson

Member
Licensed User
Longtime User
Add a reference to the Http library.
Thanks, Erel, but I suspect there's more to it than that.

Once I've added the http library, what else do I have to do? Will the call to "job2.GetRequest.SetContentType("application/json")" then stop causing an error, or will I then have a routine somewhere that I can edit as described in your post?
 
Upvote 0

pjetson

Member
Licensed User
Longtime User
Thanks, Erel. Adding the reference to the Http library fixed that problem.

Is there any way to determine the HTTP status code that is returned from a POST? For example, the web server returns codes like 200 for success, 201 for Object Created, and so on.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…