我试图改变使用网站的API的文章内的价格上传 它的文档是在https://www.mkmapi.eu/ws/documentation/API_1.1:Stock试图用PUT请求
在运行的时候,我得到一个错误417预期类失败,这是从文档中描述如下: 通常情况下,当您的请求具有不带相应标头和/或主体不作为文本发送的XML主体时,您将收到417 Expectation Failed HTTP状态代码,但其字节表示形式。 417的另一个可能的原因是,当您发送超过1.024字节的主体数据而不添加标头Expect:您的请求。
任何帮助,将不胜感激。我也应该说认证不是我可以下载我的文章价格的问题。
public void UpdateMarketPrice(string MarketID, string NewPrice)
{
// https://www.mkmapi.eu/ws/documentation/API_1.1:Stock
String finalResult;
String method = "PUT";
String url = "https://www.mkmapi.eu/ws/v1.1/stock";
HttpWebRequest request = WebRequest.CreateHttp(url) as HttpWebRequest;
OAuthHeader header = new OAuthHeader();
request.Headers.Add(HttpRequestHeader.Authorization, header.getAuthorizationHeader(method, url));
request.Method = method;
request.ContentType = "text/xml; encoding='utf-8'";
XElement xmlDoc =
new XElement("request",
new XElement("article",
new XElement("idArticle", MarketID),
new XElement("idLanguage", 1),
new XElement("comments", "Edited through the API"),
new XElement("count", 7),
new XElement("price", 11),
new XElement("condition", "NM"),
new XElement("isFoil", false),
new XElement("isSigned", false),
new XElement("isPlayset", false)
)
);
String finalXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + xmlDoc.ToString();
MessageBox.Show(finalXML);
byte[] bytes = Encoding.ASCII.GetBytes(finalXML);
request.ContentLength = bytes.Length;
using (Stream putStream = request.GetRequestStream())
{
putStream.Write(bytes, 0, bytes.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
finalResult = reader.ReadToEnd();
}
MessageBox.Show(finalResult);
}
惊人的作品!非常感谢! –
很高兴听到它的作品!我昨天实际遇到了与mkmapi相同的问题,但自从我工作以来,我没有时间为自己尝试这种溶剂。 – Tim