使用HTTPClient发布图像,但也在Windows Phone上发布一些参数

时间:2015-05-29 16:02:39

标签: c# windows-phone httpclient multipartform-data

我想要 String s1Value; s1.setAdapter(adapter); s1.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected( AdapterView<?> parent, View view, int position, long id) { s1Value = adapter.get(position); } public void onNothingSelected(AdapterView<?> parent) { s1Value = ""; } }); 次请求。但我也希望通过它来传递很多参数。当我正在做一个帖子时,我这样做:

MultipartFormDataContent

这很完美。但现在我也想用它传递一个图像。 我找到了很多例子,但总是没有额外的参数。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

HttpClient httpClient = new HttpClient();

MultipartFormDataContent content = new MultipartFormDataContent();

content.Add(new StringContent(parameter), "name");

content.Add(new StreamContent(stream), "param", "filename");

HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(address, content);