java 怎么接收http请求
展开全部
HttpURLConnection mHttpURLConnection = null;
URL mUrl = null;
InputStream inputStream = null;
try {
String url = UrlEncode(mFileType.getStrUrl(), "UTF-8");
//mUrl = new URL(mFileType.getStrUrl());
mUrl = new URL(url);
mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
mHttpURLConnection.setAllowUserInteraction(true);
mHttpURLConnection.setRequestMethod("GET");
mHttpURLConnection.setRequestProperty("Range", "bytes=" + startPos
+ "-" + endPos);
mHttpURLConnection.setRequestProperty("Connection", "Keep-Alive");
int responseCode = mHttpURLConnection.getResponseCode();
long length = mHttpURLConnection.getContentLength();
// 判断请求是否成功处理
if (responseCode == HttpStatus.SC_OK||responseCode == HttpStatus.SC_PARTIAL_CONTENT) {
inputStream = mHttpURLConnection.getInputStream();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URL mUrl = null;
InputStream inputStream = null;
try {
String url = UrlEncode(mFileType.getStrUrl(), "UTF-8");
//mUrl = new URL(mFileType.getStrUrl());
mUrl = new URL(url);
mHttpURLConnection = (HttpURLConnection) mUrl.openConnection();
mHttpURLConnection.setAllowUserInteraction(true);
mHttpURLConnection.setRequestMethod("GET");
mHttpURLConnection.setRequestProperty("Range", "bytes=" + startPos
+ "-" + endPos);
mHttpURLConnection.setRequestProperty("Connection", "Keep-Alive");
int responseCode = mHttpURLConnection.getResponseCode();
long length = mHttpURLConnection.getContentLength();
// 判断请求是否成功处理
if (responseCode == HttpStatus.SC_OK||responseCode == HttpStatus.SC_PARTIAL_CONTENT) {
inputStream = mHttpURLConnection.getInputStream();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你需要搭建一个服务器,才能接受http请求。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getAttribute("键名");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Java 中的servlet
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询