I am using android-async-http and really liking it. I've run into a problem with POSTing data. I have to post data to the API in the following format: -
<request>
<notes>Test api support</notes>
<hours>3</hours>
<project_id type="integer">3</project_id>
<task_id type="integer">14</task_id>
<spent_at type="date">Tue, 17 Oct 2006</spent_at>
</request>
As per the documentation, I tried doing it using RequestParams
, but it is failing. Is this any other way to do it? I can POST equivalent JSON too. Any ideas?
a better way to post json
To post XML
If someone have a problem that httpclient send as
Content-Type: text/plain
, please refer this link: https://stackoverflow.com/a/26425401/361100The loopj httpclient is somewhat changed (or has problem) which cannot override
StringEntity
native Content-Type toapplication/json
.You can add the JSON string as an InputStream of some kind - I've used the ByteArrayStream, then passing it to the RequestParams you should set the correctMimeType
@Timothy answer did not work for me.
I defined the
Content-Type
of theStringEntity
to make it work:Good Luck :)
To post xml file to a php server :
}
After adding android-async-http-1.4.9.jar to android studio, go to build.gradle and add :
compile 'com.loopj.android:android-async-http:1.4.9'
under dependenciesAnd on AndroidManifest.xml add:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />