2017-03-28 9 views
0

WebAPIを呼び出すC#デスクトップアプリケーションを作成しています。 1つの関数はファイルをアップロードし、パラメータを持ちます。WebAPI c#デスクトップアプリケーションから呼び出されるパラメータを使用したファイルアップロード機能

MultipartFormDataContentを使用する例が見つかりましたが、呼び出しにパラメータがある場合は動作させることができません。

PostAsyncを設定して、MultiFormDataContentパラメータとurlパラメータの両方をコンテンツに含めるようにし、それらをrequestURIの一部として埋め込まないようにするにはどうすればよいですか?

//this works with the first API call 
    HttpClient client = new HttpClient(); 
    client.BaseAddress = new Uri("www.someURL/APICalls/"); 
    var content = new MultipartFormDataContent(); 
    content.Add(new StreamContent(fileStream), "\"file\"", string.Format("\"{0}\"", fileInfo.Name)); 
    //adding the following line doesn't work with the second API function, it can't find the API function to call. 
    //content.Add(new StringContent("12345"), "toolToken"); 

    Task taskUpload = client.PostAsync("UploadFileTest", content).ContinueWith(task => 
    {... 

答えて

0

それを呼び出す

API関数

//Can Call this 
    [HttpPost] 
    [Route("UploadFileTest")] 
    public async Task<HttpResponseMessage> UploadFileTest() 
    {... 

    //How to do this 
    [HttpPost] 
    [Route("UploadFileTest")] 
    public async Task<HttpResponseMessage> UploadFileTest(string toolToken) 
    {... 

C#が体responce API内部サーバーエラーがスローされます[FromBody]

[HttpPost] 
[Route("UploadFileTest")] 
public async Task<HttpResponseMessage> UploadFileTest([FromBody]string toolToken) 
{... 
+0

を試してみてください。そして、私は他のWeb呼び出しで使用されているように、既存の関数を使用したいと思います。 – runfastman

+0

'API Internal Server Error responce body' - クライアントに送信するレスポンスを作成するときに問題になります。 –

+0

'既存の関数'とはどういう意味ですか?属性を追加したくないのですか? –

関連する問題