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;}}展开全部建web项目,放在tomcat里面跑