导航:首页 > 编程语言 > javahttp客户端

javahttp客户端

发布时间:2023-02-12 11:51:32

A. java http可以websocket不行

解决方案如下:
因为HTTPS是基于SSL依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密,所以在HTTPS站点调用某些非SSL验证的资源时浏览器可能会阻止。
方案一:假设HTTPS站点使用Nginx服务器,其他服务器也是类似的思路,可以用服务器代理ws服务,可以用nginx的WebSocket proxying。
这样客户端请求的是wss://服务器,通过nginx的WebSocket proxying代理到实际不支持ssl的websocket服务器。
方案二:直接为WebSocket服务器增加ssl证书,这样就可以直接通过wss://来请求服务器了,以swoole为例,其他服务器也是类似的思路。

B. 如何使用java实现基于Http协议的大文件传输

虽然在JDK的java.net包中已经提供了访问HTTP协议的基本功能,但是对于大部分应用程序来说,JDK库本身提供的功能还不够丰富和灵活。HttpClient是ApacheJakartaCommon下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议。以下是简单的post例子:Stringurl="bbslogin2.php";PostMethodpostMethod=newPostMethod(url);//填入各个表单域的值NameValuePair[]data={newNameValuePair("id","youUserName"),newNameValuePair("passwd","yourPwd")};//将表单的值放入postMethod中postMethod.setRequestBody(data);//执行postMethodintstatusCode=httpClient.executeMethod(postMethod);//HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发//301或者302if(statusCode==HttpStatus.SC_MOVED_PERMANENTLY||statusCode==HttpStatus.SC_MOVED_TEMPORARILY){//从头中取出转向的地址HeaderlocationHeader=postMethod.getResponseHeader("location");Stringlocation=null;if(locationHeader!=null){location=locationHeader.getValue();System.out.println("Thepagewasredirectedto:"+location);}else{System.err.println("Locationfieldvalueisnull.");}return;}详情见:/developerworks/cn/opensource/os-httpclient/

C. java http 客户端有哪些

1、Apache httpcomponents-client
2、Apache commons-httpclient
3、Apache HttpAsyncClient

D. Java客户端通过Http发送POST请求上传文件

要按http的multi-part上传的。接收端,再按multi-part解析成文件流

E. 客户端(C#)通过HTTP协议怎么向服务器端(java)传送文件(常用的是图片) ,服务器端又怎么解析

private string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
{
string ret = string.Empty;
try
{
byte[] byteArray = dataEncode.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
webReq.Method = "POST";
webReq.ContentType = "application/x-www-form-urlencoded";

webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return ret;
}

F. 请教http摘要认证客户端的Java实现

HttpURLConnection hc = null;
try
{
hc = (HttpURLConnection) new URL(url).openConnection();
hc.setConnectTimeout(10000);
hc.setReadTimeout(10000);
hc.setDoInput(true);
hc.setDoOutput(true);
hc.setUseCaches(false);

String content = param;
DataOutputStream out = new DataOutputStream(hc.getOutputStream());

out.writeBytes(content);
out.flush();
out.close();
//从hc中取出sessionId
for (int i = 1; (key = hc.getHeaderFieldKey(i)) != null; i++)
{
if (key.equalsIgnoreCase("Set-Cookie"))
{
sessionId = hc.getHeaderField(key);
sessionId = sessionId.substring(0, sessionId.indexOf(";"));
break;
}
}
BufferedReader reader = new BufferedReader(
new InputStreamReader(hc.getInputStream()));
String lines;
while ((lines = reader.readLine()) != null)
{
break;
}

reader.close();
catch (Exception e)
{
//
//e.printStackTrace();
return false;
}
finally
{
// 断开连接
hc.disconnect();
}

阅读全文

与javahttp客户端相关的资料

热点内容
数据库查询系统源码 浏览:617
php5314 浏览:357
完美国际安装到哪个文件夹 浏览:668
什么app可以扫一扫做题 浏览:538
程序员编码论坛 浏览:923
淘点是什么app 浏览:659
中国高等植物pdf 浏览:453
51单片机时间 浏览:182
后台如何获取服务器ip 浏览:267
单片机流水灯程序c语言 浏览:234
程序员第二职业挣钱 浏览:238
运行里怎么输入服务器路径 浏览:840
pythonstepwise 浏览:509
刘一男词汇速记指南pdf 浏览:64
php认证级别 浏览:368
方舟编译啥时候推送 浏览:1011
php手机验证码生成 浏览:675
哲学思维pdf 浏览:14
凌达压缩机有限公司招聘 浏览:534
weblogic命令部署 浏览:37