java怎么实现http服务器怎么解决
展开全部
参数:url:目标地址data:要post的数据比如a=1&b=2publicstringGetPostString(stringurl,stringdata){try{byte[]postBytes=Encoding.GetEncoding("utf-8").GetBytes(data);HttpWebRequestmyRequest=(HttpWebRequest)WebRequest.Create(url);myRequest.Method="POST";myRequest.ContentType="text/html";myRequest.ContentLength=postBytes.Length;myRequest.Proxy=null;StreamnewStream=myRequest.GetRequestStream();newStream.Write(postBytes,0,postBytes.Length);newStream.Close();//GetresponseHttpWebResponsemyResponse=(HttpWebResponse)myRequest.GetResponse();using(StreamReaderreader=newStreamReader(myResponse.GetResponseStream(),Encoding.GetEncoding("utf-8"))){stringcontent=reader.ReadToEnd();returncontent;}}catch(System.Exceptionex){returnex.Message;}}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询