var baseUrl = "http://localhost:449/testweb";
var userName = "administrator";
var password = "123456";
HttpWebRequest rq = HttpWebRequest.Create(baseUrl + "/api/GetUserToken") as HttpWebRequest;
rq.Method = WebRequestMethods.Http.Post;
rq.Accept = "application/json";
rq.ContentType = "application/json";
var loginStr = "{userName:\"" + userName + "\", password:\"" + password + "\"}";
var
data = Encoding.UTF8.GetBytes(loginStr);
using (Stream stream = rq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = rq.GetResponse();
var token = new StreamReader(response.GetResponseStream()).ReadToEnd();
if(token.StartsWith("Error:"))
{
MessageBox.Show(token);
return;
}
Process.Start(baseUrl + "?token=" + token);
这段获取token的c#代码转成foxtable的提示报错 System.Net.WebException: 远程服务器返回错误: (411) 所需的长度。
代码如下 ,请老师帮忙看看 排版有问题,代码放到附件了
Dim username As String = "Administrator"
Dim password As String = "123456"
Dim hc As New HttpClient("http://localhost:449/testweb/api/GetUserToken")
Dim jstr As String = "{""userName"":""" & userName & """, ""password"":""" & password & """}"
hc.Method = "post"
hc.Accept = "application/json"
hc.C
hc.FormData.Add("GetUserToken", jstr)
Dim ret As String = hc.getdata()
output.show(ret.ToString())
[此贴子已经被作者于2024/11/20 20:36:02编辑过]
此主题相关图片如下:微信图片_20241121161055.png
加上hc.ContentType = "application/json"
此主题相关图片如下:微信图片_20241121193401.png
还是不行
此主题相关图片如下:微信截图_20241121193934.png
改成这种也是不行
此主题相关图片如下:微信图片_20241121194226.png
网上是这么说的,但是FT里的httpclient好像没有length参数