C# Prestashop-在c中上载图像web服务#
我正在为一家公司开发一款应用程序。因此,对于应用程序,他们希望将图像上传到prestashop。问题基本上是,我无法通过web服务实现这一点。我总是得到一个错误66:C# Prestashop-在c中上载图像web服务#,c#,image,post,prestashop,C#,Image,Post,Prestashop,我正在为一家公司开发一款应用程序。因此,对于应用程序,他们希望将图像上传到prestashop。问题基本上是,我无法通过web服务实现这一点。我总是得到一个错误66: <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <errors> <error> <code> <![CDATA[66]]&
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code>
<![CDATA[66]]>
</code>
<message>
<![CDATA[Unable to save this image]]>
</message>
</error>
</errors>
</prestashop>
我什么都试过了(邮递员、httpclient、webclient)。唯一有效的是Prestasharp图书馆。然而,我的老板不想依赖外部库来开发这个应用程序。(是的,我也不明白)。因此,我想知道是否有人可以告诉我如何上传没有图书馆的图像。
例如,下面的代码不起作用,但我认为它是正确的
string file = @"C:\Users\MyPC\Pictures\Example\50.jpg";
string webAddress = @"http://mywebsite.com/api/images/products/1?ws_key=NUZSHHQ1X456IJQDPXY3GUXG2C6AMAV3";
var client = new HttpClient();
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("image", file)
};
var content = new FormUrlEncodedContent(pairs);
MessageBox.Show( client.PostAsync(webAddress, content).Result.ReasonPhrase );
string file=@“C:\Users\MyPC\Pictures\Example\50.jpg”;
字符串webAddress=@“http://mywebsite.com/api/images/products/1?ws_key=NUZSHHQ1X456IJQDPXY3GUXG2C6AMAV3";
var client=新的HttpClient();
var pairs=新列表
{
新的KeyValuePair(“图像”,文件)
};
var内容=新FormUrlEncodedContent(成对);
Show(client.PostAsync(webAddress,content.Result.ReasonPhrase);
我见过有人抱怨同一件事,但从来没有人解决过这个问题
我希望你们能成功
最亲切的问候好吧,我终于用RestSharp解决了这个问题
public string uploadImage(string path, string id_product)
{
var client = new RestClient("http://mywebsite.com/api");
byte[] file = System.IO.File.ReadAllBytes(path);
var request = new RestRequest("images/products/" + id_product + "?ws_key=" + API_KEY, Method.POST);
request.AddFileBytes("image", file, Path.GetFileName(path));
IRestResponse response = client.Execute(request);
string content = response.Content;
return content;
}
我陷入困境的部分是AddFileBytes
方法
希望它能帮助别人