2013-02-04 2 views
1

Base API에서 응답을 보내려고하지만 "500 Internal Server Error"오류가 계속 발생합니다. 적어도 401 HTTP Response를 얻고 싶습니다. 즉, 인증 호출에 실패했습니다. 여기기본 CRM API 인증에서 응답을 얻는 방법

http://dev.futuresimple.com/api/authentication

그리고 내 코드입니다 : -이 요청 본문의 유형입니다

public string Authenticate() 
     { 
      string result = ""; 
      string url = "https://sales.futuresimple.com/api/v1/"; 
      string email = "[email protected]"; 
      string password = "pass"; 
      string postData = "email=" + email + "&password=" + password; 
      HttpWebRequest request = null; 
      Uri uri = new Uri(url + "authentication.xml"); 
      request = (HttpWebRequest)WebRequest.Create(uri); 
      request.Method = "POST"; 
      request.ContentType = "application/xml"; 
      request.ContentLength = postData.Length; 

      using (Stream writeStream = request.GetRequestStream()) 
      { 
       UTF8Encoding encoding = new UTF8Encoding(); 
       byte[] bytes = encoding.GetBytes(postData); 
       writeStream.Write(bytes, 0, bytes.Length); 
       writeStream.Close(); 
      } 

      try 
      { 
       using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 
       { 
        using (Stream responseStream = response.GetResponseStream()) 
        { 
         using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8)) 
         { 
          result = readStream.ReadToEnd(); 
         } 
        } 
       } 
      } 
      catch (WebException ex) 
      { 
       ex = ex; 
      } 
      return result; 
     } 

답변

1

당신은 ContentTypeapplication/xml에 설정하고 여기 자료 API 인증을 사용하여 설명입니다. 보내는 신체 (string postData = "email=" + email + "&password=" + password;)는 xml 대신 폼 인코딩됩니다. 라인 request.ContentType = "application/xml";을 건너 뛰는 것이 트릭을 수행해야합니다. 또는 요청 본문을 xml로 인코딩 할 수도 있습니다.

관련 문제