POST是否足够安全以发送登录凭据?
或者是必须的SSL连接?
我有一个正常工作的Web请求,但它只是返回状态OK,但我需要我要求它返回的对象.我不知道如何获取我要求的json值.我是新手使用对象HttpClient,有没有我错过的属性?我真的需要返回的对象.谢谢你的帮助
进行调用 - 运行正常返回状态OK.
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var responseMsg = client.GetAsync(string.Format("http://localhost:5057/api/Photo")).Result;
Run Code Online (Sandbox Code Playgroud)
api get方法
//Cut out alot of code but you get the idea
public string Get()
{
return JsonConvert.SerializeObject(returnedPhoto);
}
Run Code Online (Sandbox Code Playgroud) 这是我第一次曾经使用JSON,甚至System.Net
和WebRequest
部分在我的任何应用程序.我的应用程序应该发送一个JSON有效负载,类似于下面的一个到身份验证服务器:
{
"agent": {
"name": "Agent Name",
"version": 1
},
"username": "Username",
"password": "User Password",
"token": "xxxxxx"
}
Run Code Online (Sandbox Code Playgroud)
为了创建这个有效载荷,我使用了JSON.NET
库.我如何将此数据发送到身份验证服务器并接收其JSON响应?以下是我在一些示例中看到的内容,但没有JSON内容:
var http = (HttpWebRequest)WebRequest.Create(new Uri(baseUrl));
http.Accept = "application/json";
http.ContentType = "application/json";
http.Method = "POST";
string parsedContent = "Parsed JSON Content needs to go here";
ASCIIEncoding encoding = new ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(parsedContent);
Stream newStream = http.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
var response = http.GetResponse();
var stream = response.GetResponseStream();
var sr = new StreamReader(stream);
var …
Run Code Online (Sandbox Code Playgroud) 我正在对一个Web应用程序进行压力测试,并设置了一个Windows测试程序,该程序可以旋转多个线程并在每个线程上发出Web请求.
问题是我得到以下输出:
01/09/09 11:34:04 Starting new HTTP request on 10
01/09/09 11:34:04 Starting new HTTP request on 11
01/09/09 11:34:04 Starting new HTTP request on 13
01/09/09 11:34:05 Starting new HTTP request on 14
01/09/09 11:34:05 Starting new HTTP request on 11
01/09/09 11:34:05 11 has finished!
01/09/09 11:34:05 Starting new HTTP request on 13
01/09/09 11:34:05 13 has finished!
01/09/09 11:34:05 Starting new HTTP request on 14
01/09/09 11:34:05 14 has finished!
01/09/09 11:34:05 Starting new HTTP request on …
Run Code Online (Sandbox Code Playgroud) 如果我想将值列表添加为HTTP标头,是否有标准方法可以执行此操作?我在RFC 822中找不到任何东西(我可以很容易理解).例如,逗号分隔值是标准值还是分号分隔值.有标准吗?
例:
Key: value1;value2;value3
Run Code Online (Sandbox Code Playgroud) 我的客户通过他们的SSL和Internet Explorer了解了我的问题.他们说他们在访问URL时会遇到信任问题.
我通过HTTPS访问JSON.该网站位于一台服务器上,我在本地计算机上使用控制台应用程序.我试图绕过SSL证书,但是,我的代码仍然失败.
我可以改变HttpWebRequest来解决这个问题吗?
我使用此代码得到此错误:
// You must change the URL to point to your Web server.
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
req.AllowAutoRedirect = true;
// allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebResponse respon = req.GetResponse();
Stream res = respon.GetResponseStream();
string ret = "";
byte[] buffer = new byte[1048];
int read = 0;
while ((read = res.Read(buffer, 0, buffer.Length)) > 0)
{
//Console.Write(Encoding.ASCII.GetString(buffer, 0, read));
ret += Encoding.ASCII.GetString(buffer, 0, read);
} …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个WebClient库.现在我正在实现一个代理功能,所以我正在进行一些研究,我看到一些使用该CONNECT
方法请求URL的代码.
但是在我的Web浏览器中检查它,它不使用该CONNECT
方法,而是调用GET方法.
所以我很困惑.当我应该使用这两种方法?
相关:how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https
如何在C#中发送HTTPS GET请求?
我相信经过长时间的研究和搜索,我发现我想做的事情可能更好,通过建立一个异步连接并在所需的超时后终止它......但我会继续问,无论如何!
快速代码片段:
HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest.Create(url);
webReq.Timeout = 5000;
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
// this takes ~20+ sec on servers that aren't on the proper port, etc.
Run Code Online (Sandbox Code Playgroud)
我有一个HttpWebRequest
多线程应用程序中的方法,我连接到大量的公司Web服务器.在服务器没有响应的情况下HttpWebRequest.GetResponse()
,即使我指定的超时仅为5秒,大约需要20秒才能超时.为了定期通过服务器,我想跳过连接时间超过5秒的服务器.
所以问题是:"是否有一种简单的方法来指定/减少WebRequest或HttpWebRequest的连接超时?"
我正在尝试接受压缩响应的请求
var request = (HttpWebRequest)HttpWebRequest.Create(requestUri);
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
Run Code Online (Sandbox Code Playgroud)
我想知道当我添加第二行时,我将不得不手动处理解压缩.
httpwebrequest ×10
c# ×6
.net ×4
ssl ×2
asp.net ×1
deflate ×1
gzip ×1
http ×1
http-headers ×1
http-proxy ×1
http-request ×1
json ×1
json.net ×1
post ×1
proxy ×1
proxy-server ×1
security ×1
timeout ×1