HttpClient SyncPost 返回“Web 服务方法名称无效”
我绝对是Newby来依靠API的内容,并且我尝试将带有XML主体的帖子到服务器上。服务器还可以(我可以为多样化的呼叫获得一些响应),但是当我尝试发表帖子时,我会得到“方法名称无效”。我看不到有什么问题...
这是我的代码(C#)的一部分:
string post_body = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
"<mark> " +
$"<idMark>{idMark}</idMark> " +
$"<idClipLog>{idClipLog}</idClipLog> " +
$"<freeDescription>{freeDescription}</freeDescription> " +
$"<tcOut>{tcOut}</tcOut> " +
$"<tcIn>{tcIn}</tcIn> " +
"<clipLogOperator> " +
$"<OperatorName>{operatorName}</OperatorName>" +
"</clipLogOperator>" +
"<clipLogLayer>" +
$"<layerName>{layerName}</layerName>" +
"</clipLogLayer>" +
"<markKeyword>" +
$"<idMark>{idMKMark}</idMark>" +
$"<idMarkKeyword>{idMarkKeyword}</idMarkKeyword>" +
$"<keyword>{keyword}</keyword>" +
"</markKeyword>" +
"</mark>";
var httpContent = new StringContent(post_body);
var requestUri = $"VideoTags.asmx/CreateMark";
var response = _httpClient.PostAsync(requestUri, httpContent).Result;
if (!response.IsSuccessStatusCode)
{
var xmldata = response.Content.ReadAsStringAsync();
var xmlSerializer = new XmlSerializer(typeof(cExtendedSessionsResult));
using (StringReader reader = new StringReader(xmldata.Result))
{
try
{
var logIdResp = (cExtendedSessionsResult)xmlSerializer.Deserialize(reader);
}
catch
{
throw new Exception($"[E04071035] Error in CreateMark [{_server}]");
}
}
}
也许是身体内容的问题?我需要将XML传递到邮局中。我从XML创建string -content,然后传递给PostAsync调用。这是正确的吗?
httpclient似乎具有正确的baseaddress(正如我之前所说,我能够称呼一些获取功能)。
提前致谢!
I'm absolute newby to REST API's stuff, and I try to make a POST with a XML body to a server. The server is ok (I can get some responses for a diverse GET calls), but when I try to make a POST I get 'method name is not valid'. I can't see what is wrong...
This is part of my code (C#):
string post_body = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
"<mark> " +
quot;<idMark>{idMark}</idMark> " +
quot;<idClipLog>{idClipLog}</idClipLog> " +
quot;<freeDescription>{freeDescription}</freeDescription> " +
quot;<tcOut>{tcOut}</tcOut> " +
quot;<tcIn>{tcIn}</tcIn> " +
"<clipLogOperator> " +
quot;<OperatorName>{operatorName}</OperatorName>" +
"</clipLogOperator>" +
"<clipLogLayer>" +
quot;<layerName>{layerName}</layerName>" +
"</clipLogLayer>" +
"<markKeyword>" +
quot;<idMark>{idMKMark}</idMark>" +
quot;<idMarkKeyword>{idMarkKeyword}</idMarkKeyword>" +
quot;<keyword>{keyword}</keyword>" +
"</markKeyword>" +
"</mark>";
var httpContent = new StringContent(post_body);
var requestUri = quot;VideoTags.asmx/CreateMark";
var response = _httpClient.PostAsync(requestUri, httpContent).Result;
if (!response.IsSuccessStatusCode)
{
var xmldata = response.Content.ReadAsStringAsync();
var xmlSerializer = new XmlSerializer(typeof(cExtendedSessionsResult));
using (StringReader reader = new StringReader(xmldata.Result))
{
try
{
var logIdResp = (cExtendedSessionsResult)xmlSerializer.Deserialize(reader);
}
catch
{
throw new Exception(quot;[E04071035] Error in CreateMark [{_server}]");
}
}
}
Perhaps a problem with the body content? I need pass the XML in the POST body. I create StringContent from my XML and pass to PostAsync call. This is correct?
HttpClient seems have the correct BaseAddress (as I said before, I was able to call some get functions).
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢大家!最后我可以与提供商交谈,看来这是 API 接口规范中的错误。
再次感谢您!
Thanks a lot for everybody! Finally I can talk with the provider, and seems that is an error in the specification of the API interface.
Thank you again!