httpurlconnection post请求中如何能保证请求头与正文是一次发送

httpurlconnection post请求中正文是在获取inputstream的时候发送,那请求头是不是在outputsream关闭的时候发送呢,如何能保证他两是一起发送?

5个回答

            // 读取客户端数据    
            InputStream socketIn=socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(socketIn));
            String msg=null;
            int content_Length = 0;
            while((msg=br.readLine())!=null){
                System.out.println(msg);
                if(msg.contains("Content-Length")){
                    content_Length=Integer.parseInt(msg.split(":")[1].trim());
                }
                if("".equals(msg)){
                    int readSize;  
                    char[] chars = null;  
                    chars = new char[content_Length];  
                    long length_tmp = content_Length;  
                    long index = 0;// start from zero  
                    while ((readSize = br.read(chars, (int) index, (int) length_tmp)) != -1) {
                        length_tmp -= readSize;  
                        if (length_tmp == 0) {  
                            break;  
                        }  
                        index = index + readSize;// 写入字符数组的offset(偏移量)  
                    } 
                    System.out.println(new String(chars));
                }
            }

可以去了解下http协议和tcp协议

个人认为:只要是一次请求,那肯定是一起发送的。

如果你没有用range断点续传,就是一次发送的,你可以用fiddler这个工具抓包证实这一点

httpurlconnection发送请求 服务端开启socket服务接收 就会发现正文是在获取inputstream的时候发送而报头是在outputstream关闭的时候发送的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于HttpURLConnection发送Post请求
我写了如下一段代码:rnrn try rn String s="username=admin&password=123";rn URL url=new URL("http://127.0.0.1:8080/myweb/servlet/Mytest");rn HttpURLConnection httpurlconnection = null;rn httpurlconnection = (HttpURLConnection)url.openConnection();rn rn httpurlconnection.setUseCaches(false);rn httpurlconnection.setDefaultUseCaches(false);rn httpurlconnection.setDoOutput(true);rn httpurlconnection.setDoInput(true);rn httpurlconnection.setRequestMethod("POST");rn httpurlconnection.setRequestProperty("Accept", "text/html");rn httpurlconnection.setRequestProperty("Content-type", "text/html");rn httpurlconnection.setRequestProperty("Connection", "close");rn httpurlconnection.setRequestProperty("Content-Length", String.valueOf(s.length()));rn /**/rn OutputStream outputstream = httpurlconnection.getOutputStream();rn outputstream.write(s.getBytes());rn outputstream.flush();rn rn int code = httpurlconnection.getResponseCode();rn if(code != HttpURLConnection.HTTP_OK )rn rn System.out.println("error code "+ code);rn rn rn elsern rn System.out.println("ok");rn rn rn rn rn catch(Exception e)e.printStackTrace(); rn rn rn rnrn执行没有问题,但是在servlet"http://127.0.0.1:8080/myweb/servlet/Mytest"中,request.getParameter("username")却是null.不知道为什么,请帮小弟看看
【接口测试】:HttpURLConnection 发送post请求
现在根据项目的需要,已经转战服务端的测试,就先从最简单的发送post请求,获取响应数据,对json串解析 需求: 1、模拟不同国家的客户端,去请求对应国家的任务 2、模拟不同的国家IP、模拟参数 3、Post发送post的方法类,代码如下:public class HttpRequest { /** * * @param url 请求的url地址 * @
HttpURLConnection 发送PUT请求,设置请求头参数 json请求体
http请求有八中方法GET,POST,HEAD,PUT,DELETE,OPTIONS,TRACE,CONNECT,GET和POST比较常用,由于项目开发需要,开始自己研究PUT请求方法,其实和POST请求方法差不多。下面来讲一下常用的请求方法和不常用的PUT方法。    一、HEAD方法跟GET方法相同,只不过服务器响应时不会返回消息体。一个HEAD请求的响应中,HTTP头中包含的原信
HttpUrlConnection用get和post请求发送参数
post请求: final String nameValue = username.getText().toString(); final String passValue = password.getText().toString(); new Thread(){ public void run() {
利用HttpURLConnection发送post请求上传文件
在页面里实现上传文件不是什么难事,写个form,加上enctype = "multipart/form-data",在写个接收的就可以了,没什么难的,如果要用java.net.HttpURLConnection来实现文件上传,还真有点搞头.:-) 1.先写个servlet把接收到的 HTTP 信息保存在一个文件中, 看一下 form 表单到底封装了什么样...
HttpURLConnection(File) POST请求发送参数和上传文件
package com.face; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import ...
24.5.4-5 使用HttpURLConnection发送GET和POST请求
本视频是智捷课堂推出的一套“Java语言学习立体教程”的视频第三部分,读者以及观看群是初级小白,通过本视频的学习能够成为Java大牛。本主要内容包括:异常处理、集合、泛型、文件管理与I/O流、多线程编程、网络编程、Swing图形用户界面编程、 反射、注解(Annotation)和数据库编程。rn“立体教程”是包括纸质图书,电子图书,视频讲解,课件以及QQ答疑服务等。
使用HttpURlConnection 发送POST请求上传文件(带参数)
前言最近在做一个博客的小项目,需要用到文件上传,HttpClient又被Android给弃用了,图片框架暂时还没学。只能使用HttpURLConnection来上传。折腾了好久,今天终于顺利地跟后台完成了对接。因此,写这篇博客梳理一下知识。理论知识背景最早的HTTP POST是 不支持 文件上传的,给编程开发带来很多问题。但是在1995年,ietf出台了rfc1867,也就是《RFC 1867 -F
利用httpURLConnection发送post请求时报错
各位大哥,大姐们,rn我在后台用httpURLConnection发送post请求时报400,服务器无法理解请求的错误。rn但是我发送时参数为空的话就没有错误,rn但是我用浏览器访问时候地址,和参数都是正确的,这个是什么原因啊,急急急,rnpackage com.smapp.geoportal.data.dao;rnrnimport java.io.*;rnimport java.io.IOException;rnimport java.net.HttpURLConnection;rnimport java.net.URL;rnimport java.net.URLEncoder;rnrnpublic class HttpInvokerrn public static final String POST_URL = "http://126.33.8.251:7001/geonetwork/srv/cn/csw";rn public static void readContentFromPost() throws IOException rn URL postUrl = new URL(POST_URL);rn HttpURLConnection connection = (HttpURLConnection) postUrlrn .openConnection();rn connection.setDoOutput(true);rn connection.setDoInput(true);rn connection.setRequestMethod("POST");rn connection.setUseCaches(false);rn connection.setInstanceFollowRedirects(true);rn connection.setRequestProperty("Content-Type",rn "application/x-www-form-urlencoded");rn connection.connect();rn DataOutputStream out = new DataOutputStream(connectionrn .getOutputStream());rn /*rn String content =""+rn ""+rn ""+rn "2.0.2"+rn ""+rn ""+rn "application/xml"+rn ""+rn "";rn */rn // content = URLEncoder.encode(content, "utf-8");rn // String content = URLEncoder.encode("330000000000/330000000000410000/330000000000410100D://","utf-8");rn //content = URLEncoder.encode(content,"utf-8");rn // String content = "330000000000/330000000000410000/330000000000410100D://";rn String content = "";rn System.out.println(content);rn out.writeBytes(content); rn out.flush();rn out.close(); rn BufferedReader reader = new BufferedReader(new InputStreamReader(rn connection.getInputStream()));rn String line;rn while ((line = reader.readLine()) != null) rn System.out.println(line);rn rn connection.disconnect();rn rn public static void main(String[] args) rn try rn readContentFromPost();rn catch (IOException e)rn e.printStackTrace();rn rn rnrnrn这个是程序代码rn下面的时候不带参数时访问后台报的rnrnrn rnrnrn这个是带上参数报的错rn2.0.2application/xmlrnjava.io.IOException: Server returned HTTP response code: 400 for URL: http://126.33.8.251:7001/geonetwork/srv/cn/cswrn at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)rn at com.smapp.geoportal.data.dao.HttpInvoker.readContentFromPost(HttpInvoker.java:46)rn at com.smapp.geoportal.data.dao.HttpInvoker.main(HttpInvoker.java:55)
httpURLConnection 模拟post请求 发送图片 在Action中怎么接?
httpURLConnection 模拟post请求 发送图片 在Action中怎么接?rn[code=Java]rn public String uploadBitmap1(String urlString,byte[] imageBytes)rn String endString = "\r\n";rn String twoHyphen = "--";rn String boundary = "*****";rn rn try rn URL url = new URL(urlString);rn HttpURLConnection con = (HttpURLConnection)url.openConnection();rn //con.setRequestProperty("content-type", "text/html");rn //允许input、Output,不使用Cachern con.setDoInput(true);rn con.setDoOutput(true);rn con.setUseCaches(false);rn rn //设置传送的method=POSTrn con.setRequestMethod("POST");rn rn //setRequestPropertyrn con.setRequestProperty("Connection", "Keep-Alive");rn con.setRequestProperty("Charset", "utf-8");rn con.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);rn rn //设置DataOutputStreamrn DataOutputStream dsDataOutputStream = new DataOutputStream(con.getOutputStream());rn dsDataOutputStream.writeBytes(twoHyphen + boundary + endString);rn dsDataOutputStream.writeBytes("Content-Disposition:form-data;" + "name=\"upload\";filename=\"" +rn "11.jpg\"" + endString);rn dsDataOutputStream.writeBytes(endString);rn rn //取得文件的FileInputStreamrn dsDataOutputStream.write(imageBytes,0,imageBytes.length);rn rn dsDataOutputStream.writeBytes(endString);rn dsDataOutputStream.writeBytes(twoHyphen + boundary + twoHyphen + endString);rnrn dsDataOutputStream.close();rn rn int cah = con.getResponseCode();rn if(cah == 200)rn InputStream isInputStream = con.getInputStream();rn int ch;rn StringBuffer buffer = new StringBuffer();rn while((ch = isInputStream.read()) != -1)rn buffer.append((char)ch);rn rn return buffer.toString();rn elsern return "false";rn rn catch (Exception e) rn e.printStackTrace();rn rn return "false";rn rnrn[/code]rnrn服务器 action中代码rn[code=Java]rnfinal long MAX_SIZE = 3 * 1024 * 1024;// 设置上传文件最大为 3Mrn rn HttpServletRequest request = ServletActionContext.getRequest (); rn DiskFileItemFactory dfif = new DiskFileItemFactory();rn dfif.setSizeThreshold(4096);// 设置上传文件时用于临时存放文件的内存大小,这里是4K.多于的部分将临时存在硬盘rn dfif.setRepository(new File(request.getRealPath("/")rn + "ImagesUploadTemp"));// 设置存放临时文件的目录,web根目录下的ImagesUploadTemp目录rnrn // 用以上工厂实例化上传组件rn ServletFileUpload sfu = new ServletFileUpload(dfif);rn // 设置最大上传尺寸rn sfu.setSizeMax(MAX_SIZE);rn // 从request得到 所有 上传域的列表rn System.out.println();rn List fileList = null;rn try rn fileList = sfu.parseRequest(request);rn catch (FileUploadException e) // 处理文件尺寸过大异常rnrn e.printStackTrace();rn rn[/code]rn接受不到啊 rn异常信息rn2010-09-02 17:23:58 [org.apache.struts2.interceptor.FileUploadInterceptor]-[ERROR] Could not find a Content-Type for upload. Verify that a valid file was submitted.rnrn因为我需要在手机上上传图片 要在网站中接受 可是上面的代码如果在Servlet中就可以接受到文件可是在Action中就被拦截 各位 有哪位懂得 给我看看 帮帮忙 谢谢了rnrnrn
perl post 请求加请求头
##给文件加星标 use LWP::UserAgent; use LWP; use Encode; use LWP::Simple; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; use HTTP::Response; use Encode; use URI::Escape; use URI::URL; use JSON;
HttpURLConnection 发送(POST)数据到服务器
URL url = new URL("http://xxx.xxx.xxx"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setConnectTimeout(8000); connect
GET与POST在请求头与请求体中的区别
一、场景简述 HTTP协议中GET请求与POST请求一直是许多初学者老生常谈的问题,但有些问题却很少有人提及,该篇博客笔者就其本质区别来做简单的阐述   二、场景实现 可以分别使用GET、POST请求来请求服务端,看看服务端的响应 1、GET请求 可以看到有General 、Response/Request 的Headers   2、POST请求 可以看到POST请求中多...
HttpURLConnection发post请求问题
要在HttpURLConnection里面发一个post请求,在请求参数中有一个checkbox多选框rn这个代码要怎么写?rn我的代码如下,测试不正常rnrn网页代码rn页面1.htmlrn rn rn rn rn rnrn想页面1_handle.jsp页面rnString[] checkbox=request.getParameterValues("checkbox");rnfor(int i=0;i
HttpURLConnection的POST请求加载数据图片
package com.example.textexercisedemo;import android.os.TransactionTooLargeException; import android.support.annotation.IdRes; import android.support.v4.app.Fragment; import android.support.v4.app.Fr
99-Android之网络请求HttpUrlConnection中Post请求
Android基础入门视频培训课程,该教程内容涵盖Android入门开发基本技能(环境搭建、Lineralayout、RelativeLayout、Button事件、Activity、启动模式等)、自定义控件(Handler、BroadCastReceiver、Notification、AlertDialog)、数据存储、网络开发(HttpClient)、android异步开发等。
HttpURLConnection的GET请求POST请求小总结
先搭建一个简单的服务器,具体方法见我另外一篇文章测试HttpUrlConnection请求时如何搭建一个简单的服务器 GET请求代码如下: //网络请求是一个耗时操作,要在子线程里面开启 new Thread(new Runnable() { @Override public void run() {
HttpURLConnection发送 http请求的工具类
文章目录HttpConnectionUtil 发送 http请求基于 HttpConnectionUtil ,将请求结果 转成 对象FastJsonTools json 与对象转换工具类 HttpConnectionUtil 发送 http请求 public class HttpConnectionUtil { /** 文本请求时所限制的最大响应长度, 5MB */ p...
【接口测试】:HttpURLConnection 发送get请求
一直在路上…… public class HttpConnectTest { URL url = null; HttpURLConnection con = null; public void test(){ try { url = new URL("http://www.kuaidi100.com/query?"
ionic4中发送post请求
Ionic4中的Get请求 学习post请求之前,必须先学习一下Get请求,重点完成Get请求中的http服务。 ①在.page.ts界面引入并声明公共服务 import { HttpHeaders,HttpClient } from '@angular/common/http'; constructor( public http:HttpClient, ) {} ...
restTemplate发送post请求时修改请求头和上传文件
1.restTemplate发送post请求时修改请求头 @PostMapping("/buyWater") public ObjectResult<String> buyWater(@RequestBody Food food) throws Exception { String url = "https://192.168.98.172/ConvertSer...
HttpURLConnection如何添加请求头?
"Content-type: application/x-www-form-urlencoded\r\nAuthorization: GoogleLogin auth=DQAAAIgAAACInuQm8vvYlY7CEJD_X1VJyLGqpRNea4rDlyHm1XFwQSnGHLiw2p0CiyaX1vRKwiC0MWXpiQVrrvvuvu_dIcV9CK5ooYjdsriB_J3AaWNz-XhGB66KrmHK7qPo3ekIBo2PDCN8bvsGcWgyvlkw7KaQwb8dM4fsaCAxwA2qpXjbRpXpCG5Qs_m96qgdxqUW7tk\r\nGData-Version: 3.0\r\n"rnrn这个是请求头的形式rnrn用HttpURLConnection实现: rnString auth = GoogleLogin auth=DQAAAHMAAACf8yuuW0db2c5Ac3p4eeSCojslxCRv_c5fOeEiFka_9zLNW7TR0oldO4AxZZS5S7FAFTMlLujuOglnnRLlmJGu5VwYrTL6WMUbWzH99MdJy_aEvC2dKlsrhwKtflZc3w8lFsEQxTyQuYTWMHPlAWEi49tPlXr4ObcNUKa2Ifg; rn_httpURLConnection.addRequestProperty("Content-type", "application/x-www-form-urlencoded");rn_httpURLConnection.addRequestProperty("Authorization", auth); // Authorizationrn_httpURLConnection.addRequestProperty("GData-Version", "3.0");rnrn但是出现下面的错误提示:rnIllegal character(s) in message header value: GoogleLogin auth=DQAAAHMAAACf8yuuW-0db2c5Ac3p4eeSCojslxCRv_c5fOeEiFka_9zLNW7TR0oldO4A-xZZS5S7FAFTMlLujuOglnnRLlmJGu5VwYrTL-6WMUbWzH99MdJy_aEvC2dKlsrhwKtflZc3w8lFsEQxTyQuYTWMHPlAWEi49tPlXr4ObcNUKa2Ifgrnrn我想问一下HttpURLConnection如何添加请求头? 不是Content-type这种定义了的头,而是另外要求的头,比如 Authorization , GData-Version rn需要setAllowUserInteraction(true)这个设置这个函数吗?rnrn这个程序是google docs的java程序
HttpClient发送post请求,和发送get请求
HttpClient发送post请求,和发送get请求
Http学习之使用HttpURLConnection发送post和get请求 android
NULL 博文链接:https://zjutsoft.iteye.com/blog/1313754
高分求教,HttpUrlConnection发送post请求,附源码
doPost方法源码如下(reqUrl为post的目标,parameters为要post的表单,recvEncoding为编码,ht为header、包括cookie的内容)rn 调用以后,用抓包软件发现post到服务器的包分成两个,一个只带header的内容,一个是我发送的数据rnrn public String doPost(String reqUrl, Map parameters, String recvEncoding,Hashtable ht) rn HttpURLConnection url_con = null;rn String responseContent = null;rn try rn StringBuffer params = new StringBuffer();rn for (Iterator iter = parameters.entrySet().iterator(); iterrn .hasNext();) rn Entry element = (Entry) iter.next();rn params.append(element.getKey().toString());rn params.append("=");rn params.append(URLEncoder.encode(element.getValue().toString(),rn recvEncoding));rn System.out.println(URLEncoder.encode(element.getValue().toString(),rn recvEncoding));rn params.append("&");rn rn rnrn if (params.length() > 0) rn params = params.deleteCharAt(params.length() - 1);rn rn rn System.out.println(params);rn byte[] b = params.toString().getBytes();rnrn URL url = new URL(reqUrl);rn url_con = (HttpURLConnection) url.openConnection();rnrn url_con.setRequestMethod("POST");rn url_con.setConnectTimeout(5000);rn url_con.setReadTimeout(5000);rn rn //设置headerrn if (ht!=null)rn Enumeration enu = ht.keys();rn while (enu.hasMoreElements())rn tryrn String f = (String)enu.nextElement();rn String v = (String)ht.get(f);rn System.out.println(String.valueOf(f)+"="+String.valueOf(v));rn if (v!=null)rn url_con.setRequestProperty(f,v);rn catch(Exception e)rn rn ht.put("Content-Length", String.valueOf(b.length)); rn rn url_con.setDoOutput(true);rn OutputStream httpOutputStream = url_con.getOutputStream();rn rn httpOutputStream.write(b);rn httpOutputStream.flush();rn httpOutputStream.close();rn rn InputStream in = url_con.getInputStream();rnrn BufferedReader rd = new BufferedReader(new InputStreamReader(in,rn recvEncoding));rn rn String tempLine = rd.readLine();rn StringBuffer tempStr = new StringBuffer();rn String crlf = System.getProperty("line.separator");rn while (tempLine != null) rn tempStr.append(tempLine);rn tempStr.append(crlf);rn tempLine = rd.readLine();rn rn responseContent = tempStr.toString();rn rd.close();rn in.close();rn catch (IOException e) rn e.printStackTrace();rn return "";rn catch(Exception e)rn e.printStackTrace();rn return "";rn finally rn if (url_con != null) rn url_con.disconnect();rn rn rn return responseContent;rn rn 抓包结果如下:rn [img=http://www.lifemessage.com.cn/a.JPG][/img]
android 原生HttpUrlConnection发送POST请求报502错误
![![图片说明](https://img-ask.csdn.net/upload/201801/16/1516085151_731208.png)图片说明](https://img-ask.csdn.net/upload/201801/16/1516085135_757331.png)
(转)Http学习之使用HttpURLConnection发送post请求深入
转自:http://blog.csdn.net/pandazxx/article/details/1660008   本节深入学习post请求。上节说道,post请求的OutputStream实际上不是网络流,而是写入内存,在getInputStream中才真正把写道流里面的内容作为正文与根据之前的配置生成的http request头合并成真正的http request,并在此时才真正向服务器...
用HttpURLConnection向一个网页发送 POST请求?
网页好像使用PHP做的,帮忙看看下面的代码,怎么老是返回登陆的界面?对编码有什么要求吗?rnimport java.net.*;rnimport java.io.*;rnrnrnpublic class DoPostURLConnectionrnrnpublic static void main(String args[])rnrntryrnrnURL url = new URL("http://www.xiaonei.com/Login.do");rnHttpURLConnection uc =(HttpURLConnection) url.openConnection();rnuc.setDoOutput(true);rnrnOutputStream raw = uc.getOutputStream();rnOutputStream buf = new BufferedOutputStream(raw);rnOutputStreamWriter out = new OutputStreamWriter(buf, "UTF-8");rnrnrnString info="email=email&password=ps";rnout.write(info);rnout.flush();rnout.close();rnrnInputStream in = uc.getInputStream();rnin = new BufferedInputStream(in);rnReader r = new InputStreamReader(in,"UTF-8");rnint c;rnSystem.out.println("==================Beging====================");rnwhile((c = r.read()) != -1)rnSystem.out.print((char) c);rnin.close();rnSystem.out.println("===================End======================");rnrnrncatch(IOException e)rnSystem.out.println("no");rnrnrnrnrn
Http学习之使用HttpURLConnection发送post请求深入
转载自:http://blog.csdn.net/pandazxx/archive/2007/06/20/1660008.aspx   本节深入学习post请求。 上节说道,post请求的OutputStream实际上不是网络流,而是写入内存,在 getInputStream中才真正把写道流里面的内容作为正文与根据之前的配置生成的http request头合并成真正的http reque...
HttpURLConnection发送post请求上传文件,文件为空?
我用HttpURLConnection来上传文件,上传来的word文件里面有字符,却什么也不显示,空白的,这是怎么一回事儿啊?rnrn我代码如下:rn String filename = "D:/ha.txt";rn try rn String BOUNDARY = "---------7d4a6d158c9"; // 数据分隔线rn URL url = new URL("http://127.0.0.1/JobPro/uploadprov.do");rn HttpURLConnection conn = (HttpURLConnection) url.openConnection();rn // 发送POST请求必须设置如下两行rn conn.setDoOutput(true);rn conn.setDoInput(true);rn conn.setUseCaches(false);rn conn.setRequestMethod("POST");rn conn.setRequestProperty("connection", "Keep-Alive");rn conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");rn conn.setRequestProperty("Charsert", "UTF-8"); rn conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);rn rn OutputStream out = new DataOutputStream(conn.getOutputStream());rn File file = new File(filename);rn rn StringBuilder sb = new StringBuilder(); rn sb.append("--"); rn sb.append(BOUNDARY); rn sb.append("\r\n"); rn sb.append("Content-Disposition: form-data;name=\"myfile\";filename=\""+ file.getName() + "\"\r\n"); rn sb.append("Content-Type:application/octet-stream\r\n\r\n"); rn rn byte[] data = sb.toString().getBytes();rn byte[] end_data = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();rn out.write(data);rn DataInputStream in = new DataInputStream(new FileInputStream(file));rn int bytesOut = 0;rn byte[] bufferOut = new byte[1024];rn while ((bytesOut = in.read()) != -1) rn out.write(bufferOut, 0, bytesOut);rn rn rn out.write(end_data);rn out.flush(); rn out.close(); rn in.close();rn rn // 定义BufferedReader输入流来读取URL的响应rn BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));rn String line = null;rn while ((line = reader.readLine()) != null) rn System.out.println(line);rn rnrn catch (Exception e) rn System.out.println("发送POST请求出现异常!" + e);rn e.printStackTrace();rn
node 发送post请求
node 发送post请求 前面写过一篇介绍 node搭建服务器、写接口、调用接口、解决跨域的文章,今天继续为大家分享如何用node做post请求。 今天的内容将以截图的形式给大家展示,为了大家能学好,建议自己动手敲一下。 这里用到了express的中间件 body-parser 来解析post 请求发送来的数据。 先安装再说 :  npm install body-p
发送post请求问题?
有哪位大牛指导一下,这个问题困扰我半天了!我在跟其他公司的一个系统进行对接时,给对方系统发送一个post的请求rn这是我的写的方法:rntry rn URL url = new URL( "https://epcis-ptp-stg.dmzstg.pingan.com.cn:19443/epcis.ptp.partner.getAhsEPolicyPDFWithCert.do?"); rn URLConnection connection = url.openConnection(); rn connection.setDoOutput(true); rn //发送域信息 rn OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "8859_1"); rn out.write( "umCode="+umCode+"&validateCode="+validateCode+"&policyNo="+policyNo+"&isSeperated="+isSeperated+"&curTime="+curTime+"&signValue="+signValue);//这里组织域信息 rn out.flush(); rn out.close(); rn //获取返回数据 rn InputStream in = connection.getInputStream(); rnrn catch (MalformedURLException e) rn // TODO Auto-generated catch block rn e.printStackTrace(); rn catch (UnsupportedEncodingException e) rn // TODO Auto-generated catch block rn e.printStackTrace(); rn catch (IOException e) rn // TODO Auto-generated catch block rn e.printStackTrace(); rn rn调试后我发现:总在connection.getOutputStream()时出异常。说是证书方面的问题。错误提示是:rnjavax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetrn at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)rn at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1476)rn at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)rn at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)rn at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:847)rn at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)rn at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)rn at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)rn at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)rn at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)rn at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1038)rn at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:402)rn at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)rn at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:836)rn at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)rn at cn.com.caissa.erp.insurance.insbill.bs.impl.InsBillBs.getSignValue(InsBillBs.java:451)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:149)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:116)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:56)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)rn at $Proxy64.getSignValue(Unknown Source)rn at cn.com.caissa.erp.insurance.insbill.action.InsBillAction.getSignValue(InsBillAction.java:330)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at venus.frames.base.action.DefaultDispatchAction.service(DefaultDispatchAction.java:339)rn at venus.frames.base.action.BaseAction.execute(BaseAction.java:172)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)rn at venus.frames.base.action.DefaultServlet.process(DefaultServlet.java:191)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at gap.logOperation.util.UserInfoBuilder.doFilter(UserInfoBuilder.java:98)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.use.filter.SignonFilter.doFilter(SignonFilter.java:62)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at venus.frames.web.SetEncodingFilter.doFilter(SetEncodingFilter.java:33)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.jamonapi.JAMonFilter.doFilter(JAMonFilter.java:57)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:595)rnCaused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetrn at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:221)rn at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)rn at sun.security.validator.Validator.validate(Validator.java:203)rn at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)rn at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)rn at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:840)rn ... 60 morernCaused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetrn at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)rn at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)rn at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)rn ... 65 morern2012-10-16 11:56:58 org.apache.catalina.core.ApplicationDispatcher invokern严重: Servlet.service() for servlet jsp threw exceptionrn哪位大牛指点。。。谢了...
java发送post请求
一、依赖<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2.5</version> </dependency&amp
curl发送post请求
curl发送post请求并统计耗时 curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" -H "Content-Type:application/json" -X POST --data "{转义...
requests发送post请求
import requests, json url_mul = ‘http://httpbin.org/post’ files = {‘file’: open(’./userinfo.txt’, ‘rb’)} r = requests.post(url_mul, files=files) print® print(r.text) print(r.content) ...
https发送post请求
https发送post请求,并接收响应信息。
jQuery发送post请求
本课程是《 java就业班》系统课程的第18章,全套课程精细讲解,该课程超过其他机构30%的课程量,经过我们全套课程系统学习的同学,可轻松从事Java高级工程师或系统架构师岗位,课程提供全套代码笔记其它相关素材及答疑服务,可谓是低投资高回报!
Ajax之post请求发送
本课程是《 java就业班》系统课程的第17章,全套课程精细讲解,该课程超过其他机构30%的课程量,经过我们全套课程系统学习的同学,可轻松从事Java高级工程师或系统架构师岗位,课程提供全套代码笔记其它相关素材及答疑服务,可谓是低投资高回报!学习前或学习后有任何疑问请在课程中提问,老师看到会第一时间回复!
Ajax发送Post请求
XMLHttpRequest发送Post请求 前言 今天在使用AJAX向服务器发送POST请求时,我按照网上很多人说的,把请求内容写入JSON,但服务端却不能正确地解析。 错误描述 var xhr = new XMLHttpRequest(); …… xhr.send(JSON.stringify({ “usr” : “zcc”, “pwd” : “123456” })); 服务端收到的内容为...
PHP 发送POST请求
cURL是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如:HTTP,FTP。TELNET等。
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件