Sending Http request instances in Android (including file upload and servlet reception)

Source: Internet
Author: User

First, I wrote a java project test to send a post request: it can contain text parameters and file parameters ********************************* *******************

Copy code


The above code can successfully simulate a java client to send a post request, and the server can also receive and save files
The main method for java testing:

Copy code


I thought it was done. As a result, it was no problem to compile the program after it was transplanted to the android project.
However, if an exception is thrown during the runtime, The PostMethod class cannot be found. The org. apache. commons. httpclient. methods. PostMethod class is definitely included;
Another exception is VerifyError. I am helpless when I encounter this exception several times during development. I think the SDK is incompatible or not. Can anyone tell me ~~
As a result, I have directly analyzed the content of the http request on the Internet to build a post request, and I have also found that the content with the uploaded file is always a problem, you can directly run the post request sent by the java project above, print the request content in the servlet, and finally implement it against the concatenated string and stream! The Code is as follows:
**************************************** *******************

Copy code


**********************
Code in the button response:
**********************

Copy code



***************************
Server servlet code:
***************************

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.