2016-10-14 8 views

Antwort

0

Dies ist die Sync-implemntation aber ich hoffe, ist, was Sie brauchen

public void Send(string auth, string filePath, string developerId) 
    { 
     string payload = System.IO.File.ReadAllText(filePath); 
     var content = new StringContent(payload); 
     using (var client = new HttpClient()) 
     { 
      client.DefaultRequestHeaders.Add("Authorization", auth); 
      client.DefaultRequestHeaders.Add("Content-Type", "multipart/form-data"); 
      client.DefaultRequestHeaders.Add("Developer-Id", developerId); 
      var result = client.PostAsync("https://api.knurld.io/v1/endpointAnalysis/file", content).Result; 
      string resultContent = result.Content.ReadAsStringAsync().Result; 
     } 
    } 

Kin d Grüße

+0

für Asynchron-ähnliche Sachen, die ich will es mit Httpclient –

+0

Ich sehe !, entschuldigen uns für die falsche answerd – MrVoid

0

Für Httpclient:

async Task Send(string developerId, string pathToFile, string auth) 
    { 
     using (HttpClient c = new HttpClient()) 
     { 
      c.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(auth); 
      c.DefaultRequestHeaders.Add("Developer-Id", developerId); 
      var multipartFormDataContent = new MultipartFormDataContent(); 
      using (Stream fileStream = new FileStream(pathToFile, FileMode.Open)) 
      { 
       multipartFormDataContent.Add(new StreamContent(fileStream)); 
       HttpResponseMessage httpResponse = await c.PostAsync(@"https://api.knurld.io/v1/endpointAnalysis/file", multipartFormDataContent); 
       string response = await httpResponse.Content.ReadAsStringAsync(); 
      } 
     } 
    }