java POST method
来源:互联网 发布:爱拍录屏软件 编辑:程序博客网 时间:2024/06/08 12:16
import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.net.URLConnection;import java.net.URLEncoder; import javax.net.ssl.HttpsURLConnection; String USER_AGENT = "Mozilla/5.0";String urlParameters = "web_username="+URLEncoder.encode("user@hotmail.net")+"&web_password="+URLEncoder.encode("R/+J2Ox5jhCAJCQdMKO8WQ==");String url = "http://www.freephoneline.ca/services/init";URL obj = new URL(url);HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest headercon.setRequestMethod("POST");con.setRequestProperty("User-Agent", USER_AGENT);con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); //String urlParameters = "sn=C02G8416DRJM&cn=&locale=&caller=&num=12345"; // Send post requestcon.setDoOutput(true);DataOutputStream wr = new DataOutputStream(con.getOutputStream());wr.writeBytes(urlParameters);wr.flush();wr.close(); int responseCode = con.getResponseCode();System.out.println("\nSending 'POST' request to URL : " + url);System.out.println("Post parameters : " + urlParameters);System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()));String inputLine;StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) {response.append(inputLine);}in.close(); //print resultSystem.out.println(response.toString());
如果是https 链接,需要把HttpURLConnection 替换为HttpsURLConnection
- java POST method
- method post 乱码
- Ajax's Post Method
- request method 'post' not supported
- wxWidgets http post method example
- Handles the HTTP POST method
- post 405 method not allowed
- Request method 'POST' not supported
- method=post和method=get的区别
- Nginx HTTP Post Method: 405 Method not allowed 解决办法
- java如何获取jsp页面上传的文件路径 20 前台jsp: <form action="AA.do?method=yktAdd" method="post" > <input type='text'
- Using POST method in XMLHTTPRequest(Ajax)
- HTTP Method小结(GET,POST.etc)
- 表单method="post"返回结果不同
- HTTP Method小结(GET,POST.etc)
- Spring MVC-Request method 'POST' not supported:
- 出现This is class 。。。,Using post method
- HTTP Method小结(GET,POST.etc)
- nologging
- Java Base64 加密解密
- 8#9 - 多校6
- C++_归并排序
- 颜色分割(待)
- java POST method
- 0808leetcode刷题总结
- 编译安装mod_jk on centOS
- XML和实体序列化和反序列化
- window下为apache注册服务
- 轻松解决GHOST XP不能安装IIS组件的小问题
- PHP中try{}catch{}的具体用法详解
- MySQL删除数据Delete与Truncate语句使用比较
- 学习Linux(三):Linux 文件管理和操作