我使用以下代码从大华XVR相机中提取记录,并成功地返回记录。
var domain = "http://IP";
var credCache = new CredentialCache();
credCache.Add(new Uri(domain), "Digest", new
NetworkCredential(username, password));
var httpClient = new HttpClient(new HttpClientHandler {
Credentials = credCache });
var result= await httpClient.GetStringAsync(new Uri(URL)); 但是,当我使用下面的代码发布记录时,它不起作用,并导致一个错误的请求。
string url = "http://IP/cgi-bin/faceRecognitionServer.cgi";
var postData = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>( "action", "addPerson"),
new KeyValuePair<string, string>("groupID", "1"),
new KeyValuePair<string, string>("name", "Test Name"),
new KeyValuePair<string, string>("birthday", "1980-01-05"),
new KeyValuePair<string, string>("sex", "Male"),
new KeyValuePair<string, string>("country", "Pakistan"),
new KeyValuePair<string, string>("province", "KPK"),
new KeyValuePair<string, string>("city", "Peshawar")
};
var content = new FormUrlEncodedContent(postData);
var domain = "http://IP";
var credCache = new CredentialCache();
credCache.Add(new Uri(domain), "Digest", new NetworkCredential(username, password));
var httpClient = new HttpClient(new HttpClientHandler { Credentials = credCache });
var result = await httpClient.PostAsync(new Uri(url), content);以上代码总是返回400个错误请求。如果有人能帮忙呢?
发布于 2021-10-29 06:42:19
我把这个问题解决如下。也许能帮上忙。
字符串url =“action=addPerson&groupID=1&name=TestName&sex=Male";字符串域= "http://IP";CredentialCache credCache =新CredentialCache {新Uri(域)、"Digest”、新NetworkCredential(用户名、密码)} };使用HttpClient client =新HttpClient(新HttpClientHandler {凭据= credCache });使用FileStream流= File.OpenRead(AppContext.BaseDirectory )。替换(“\bin\Debug\netcoreapp3.1”、“)+ "Files\14.jpg");var file_content =新的ByteArrayContent(新的ByteArrayContent=新的MediaTypeHeaderValue("image/jpeg");var response =等候client.PostAsync(url,file_content); )
https://stackoverflow.com/questions/69707109
复制相似问题