简体   繁体   中英

Simulate form post using http client in Android app?

So, I'm currently developing an app for a service which has a json-based (unfortunately) read only API . Retrieving content is no problem at all, however the only way to post content is using a form on their site which location is a PHP script. The service is open source so I know which fields the form expects, but whatever I send, it always results in a BAD REQUEST .

I captured the network traffic inside my browser and as far as I can see, the browser constructs a multipart form request, however when I copy the request and invoke it again using a REST client, a BAD REQUEST gets returned.

Is there a way to construct a http request in Android that simulates a form post?

If it's readonly I think you wouldn't be able to make requests with POST (it's assume for editing or adding things).

If you let me make you an advise, I recommend you using this project as a Library.

https://github.com/matessoftwaresolutions/AndroidHttpRestService

It makes you easy deal with apis, control network problems etc.

You can find a sample of use there.

You only have to:

  1. Build your URL
  2. Tell the component to execute in POST mode
  3. Build your JSON

As I told you, I don't know even if it will work.

I hope it helps!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM