4 years ago (2015-06-08)  Algorithm language |   First to comment  10 
post score 0 times, average 0.0
In conducting Android learning, the extremely guest needs to implement the function of login authentication, and it is required to implement http to submit data by post.The following is reproduced from the CSDN article content

Program components:

1. The client uses the eclipse HttpUtils.java standard java interface to implement HTTP post data submission. (submit username and password in post)

Focus point:

1. Public static String sendPostMessage(Map<String,String> params , String encode)

Purpose: The client sends the data params to the server, finally gets the input stream returned from the server, and finally converts the input stream into a string.Note how to use the standard java interface to implement the http post request, successfully connect to the server, and get the data returned from the server-side response.

2. Public String String changInputStream(InputStream inputStream , String encode)

Purpose: To convert an input stream into a string in the specified encoding.(In this case, the input stream InputStream returned from the server is converted to a string String encoding method encoding method)

3. Instantiation methods and iterative methods of Map<String ,String>

  • Map's instantiation method:
  • The iterative method of Map:


Program ideas:

  • 1. The client establishes the http link httpURLConnection and uses OutputStream to send data to the server
  • 2. Get the input stream InputStream returned from the server
  • 3. Convert InputStream to String

-------------------------------------------------- -------------------------------------------------- ------------

Key code:

1. Client HttpUtils.java


This article was transferred from the CSDN blog, the original http://blog.csdn.net/neu_yousei/article/details/22486983, in order to respect the author's labor results, please indicate the source.Sitelink: https://wangbaiyuan.cn/en/gojava-implementation-http-post-to-submit-data-to-the-server-2.html, if you think this article is useful to you, you can click on "Sponsored Author" below the article to reward Author!

Post comment


No Comment


Forget password?