2014-09-19 4 views
0

나는 Mailgun과 REST의 초보자이며 도움이 필요하다. 내가 검색하고 주소가 유효 여부를 그 응답을 처리하려면 어떻게mailgun 이메일 확인 응답

RestClient client = new RestClient(); 
client.BaseUrl = "https://api.mailgun.net/v2"; 
client.Authenticator = new HttpBasicAuthenticator("api", "xxxx"); 
RestRequest request = new RestRequest(); 
request.Resource = "/address/validate"; 
request.AddParameter("address", "[email protected]"); 
return client.Execute(request); 

: 내가 사용하는 경우

는 Mailgun 코드를 제공? 그냥 놀라운 Postman Chrome app 당신이 같은 요청의 결과를 볼 수 있습니다 사용하여

+0

포럼 사이트와 달리 "감사"또는 "모든 도움을 주심"또는 [so]의 서명은 사용하지 않습니다. "[안녕하세요, '고마워,'태그 라인 및 인사말을 게시물에서 삭제해야합니까?] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be 참조) . 을하지만 오류가 무엇입니까; 동적 콘텐츠 = System.Runtime.Serialization.Json.Decode (response.Content) : 컴파일러 오류 메시지 : CS0234을 : -removed-부터 게시물) –

답변

0

First of You should never post private information such as your public key of such API

:

click here이 전체 해상도

enter image description here

에 아래의 이미지를 볼 수 나는 확신을, return client.Execute(request); 대신에

var result = client.Execute(request); 
return result; 

return에 중단 점을 추가하면 호출에서 전달 된 객체가 무엇인지 검사 할 수 있습니다. 테스트하지 않고 result.Content (RestSharp가 응답 내용을 추가하는 곳)을 객체로 변환 할 수 있고 해당 객체를 사용하거나 dynamic 유형을 사용하십시오.


지금, VS에서 코드를 테스트 :

:

click here

enter image description here

당신은 다음처럼 dynamic 객체를 사용하여 전체 해상도로 아래의 이미지를 볼 수 click here 아래의 이미지를 전체 해상도로 보시려면

public void GetResponse() 
{ 
    var client = new RestClient(); 
    client.BaseUrl = "https://api.mailgun.net/v2"; 
    client.Authenticator = new HttpBasicAuthenticator("api", "pubkey-e82c8201c292691ad889ace3434df6cb"); 

    var request = new RestRequest(); 
    request.Resource = "/address/validate"; 
    request.AddParameter("address", "[email protected]"); 

    var response = client.Execute(request); 
    dynamic content = Json.Decode(response.Content); 

    bool isValid = content.is_valid; 
    string domain = content.parts.domain; 
} 

enter image description here

그냥 JSON과 같은 응답의 내용을 취급 통과 :

{ 
    "address": "[email protected]", 
    "did_you_mean": null, 
    "is_valid": true, 
    "parts": { 
     "display_name": null, 
     "domain": "mydomain.com", 
     "local_part": "me" 
    } 
} 
+0

내가 사용하고 있습니다 네임 스페이스 'System.Runtime.Serialization.Json'에 유형 또는 네임 스페이스 이름 'Decode'이 없습니다 (어셈블리 참조가 누락 되었습니까?) – user2970010

+0

addton : using Newtonsoft.Json 및 코드 변경 : 동적 내용 = JsonConvert.DeserializeObject (응답.함유량); 이제 작동합니다. – user2970010

+0

'Json.Decode'는'System.Web.Helpers'의 것입니다. 그 답이 어떤면에서 도움이 되었다면 그 답을 정답으로 표시하고 다른 사람들이 귀하의 질문에 대해 정답을 볼 수있게하십시오. – balexandre

0

이 코드는 나를 위해 작동합니다. RESTClient를 사용하지 않고 완벽하게 작동하는 내 코드를 작성했습니다.

[System.Web.Services.WebMethod] 
    public static object GetEmailInfo(string UserName) 
    { 
     var http = (HttpWebRequest)WebRequest.Create("https://api.mailgun.net/v2/address/validate?address=" + UserName); 
     http.Credentials = new NetworkCredential("api","public key"); 
     http.Timeout = 5000; 
     try 
     { 
      var response = http.GetResponse(); 
      var stream = response.GetResponseStream(); 
      var sr = new StreamReader(stream); 
      var content = sr.ReadToEnd(); 
      JSON.JsonObject js = new JSON.JsonObject(content); 
      return Convert.ToBoolean(js["is_valid"]); 
     } 
     catch (Exception ex) 
     { 

     } 
    }