2013-07-24 3 views
1

POST 요청을 만들려고하는데 작동하지 않습니다.C# HttpClient POST 요청

이/3 PARAMS, accountidentifier/유형이 요청의 형식입니다

http://someSite.com/api/User_Favorites.php?accountid=accountidentifier&type=type&seriesid=seriesid

을 seriesid 이것은 내 C#

using (var httpClient = new HttpClient()) 
     { 
      httpClient.BaseAddress = new Uri("http://somesite.com"); 
      var content = new FormUrlEncodedContent(new[] 
      { 
       new KeyValuePair<string, string>("accountidentifier", accountID), 
       new KeyValuePair<string, string>("type", "add"), 
       new KeyValuePair<string, string>("seriesid", seriesId), 

      }); 

      httpClient.PostAsync("/api/User_Favorites.php", content); 
} 

어떤 아이디어가?

+0

게시물을 호출 할 때 전체 URI가 httpClient 인 것을 디버그하여 볼 수 있습니까? –

+1

언급 한 매개 변수는'URI' ('?'다음의 질의 부분)의 일부이지만'content'로 보냅니다. – user1908061

+0

@ Cubicle.Jockey는 실제로 그것을 찾을 수 없습니다. – allocator

답변

-2

WebClient도 시도 할 수 있습니다. 브라우저에서 수행 할 작업을 정확하게 시뮬레이션하려고 시도합니다.

  var uri = new Uri("http://whatever/"); 
      WebClient client = new WebClient(); 
      var collection = new Dictionary<string, string>(); 
      collection.Add("accountID", accountID); 
      collection.Add("someKey", "someValue"); 
      var s = client.UploadValuesAsync(uri, collection); 

여기서 UploadValuesAsync는 내 컬렉션을 게시합니다.

+0

HttpClient는 기본적으로 REST API를 호출해야 할 필요성을 위해 개발 된 WebClient의 새로운 향상된 버전입니다. – user1908061

+0

@ user1908061 당신은 더 많은 것을 돕고 더 적은 불꽃을 시도해야한다. – allocator

+0

@allocator 나는 타오르는 것이 아닙니다. 여기에서는 새로운 HttpClient 클래스가 자신의 경우와 같은 경우를 위해 설계되었다고 언급했습니다. 귀하의 질문에 API를 호출하는 데 문제가 있지만 우리에게 어떤 것을 말하지는 않습니다. 당신은 스스로를 어떻게 부르는 법을 알지 못합니다. 그럼 어떻게 도와야합니까? 나는 당신의 질문에서 유일한 눈에 띄는 실수를 지적했다. – user1908061