2017-12-06 2 views
1

Twilio voice api를 사용하여 C#을 사용하여 내 콘솔 응용 프로그램에서 아웃 바운드 호출을 만들고 싶습니다. 하지만 대부분의 시간 나는 connection error 메시지를 받고 있습니다. 내 시스템에서 프록시 서버를 사용하고 있습니다. 그래서 코드와 함께 프록시 인증을 추가하고 싶습니다. 제발 제안 해주세요.Twilio voice api with C#

내 코드는 다음과 같습니다 : 여기

const string accountSid = "*****************"; 
const string authToken = "*****************"; 
var client = new TwilioRestClient(accountSid, authToken); TwilioClient.Init(accountSid, authToken); 
var to = new PhoneNumber("*****************"); 
var from = new PhoneNumber("*****************"); `enter code here` 
var call = CallResource.Create(to, from, url: new Uri(tempURL));

답변

0

Twilio 복음 전도자.

여기에서 프록시를 사용하려는 경우 Rest API를 사용하면 도움이 될 것입니다. HttpClient를 개체에 프록시 서버를 연결하려면 아래 코드를 사용해보십시오 :

public static HttpClient GetProxy() 
{ 
    // First create a proxy object 
    var proxyUri = $"{proxyServerSettings.Address}:{proxyServerSettings.Port}"; 

    var proxyCreds = new NetworkCredential("proxyuser", "proxypassword"); 

    var proxy = new WebProxy(proxyUri, false) 
    { 
     UseDefaultCredentials = false, 
     Credentials = proxyCreds, 
    }; 

    // Now create a client handler which uses that proxy 
    var httpClientHandler = new HttpClientHandler() 
    { 
     Proxy = proxy, 
     PreAuthenticate = true, 
     UseDefaultCredentials = false, 
    }; 

    return new HttpClient(httpClientHandler); 
} 

프록시와 전화 통화를하려면 여기 샘플 코드를 사용할 수 있습니다

const string accountSid = "*****************"; 
const string authToken = "*****************"; 
string to = "+1xxxxxxxxxx"; 
string from = "+1xxxxxxxxxx"; 
string callUrl = $"https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls"; 
var httpClient = GetProxy(); 
var authorizationValue = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{accountSid}:{authToken}")); 
httpClient.DefaultRequestHeaders.Clear(); 
httpClient.DefaultRequestHeaders.Add("Authorization", $"Basic {authorizationValue}"); 
var result= httpClient.PostAsync(callUrl, new FormUrlEncodedContent(new Dictionary<string,string> 
{ 
    {"To", to}, 
    {"From", from}, 
    {"Url", "http://demo.twilio.com/docs/voice.xml"} 
})); 

나를 알고하자 이것은 도움이되거나 추가 문제가 발생하는 경우에 유용합니다. 여기서 도와 드리겠습니다.

+0

twill을 전달하고 싶습니다. beacause를 사용하여 twilio의 텍스트 음성 기능을 사용하고 있습니다. var call = CallResource.Create (to, from, url : new Uri (tempURL)); 여기 tempURL은 우리가 지나가고있는 twilio twil입니다. 그래서 이것을 코드에 어떻게 포함시킬 수 있습니까? – Ajith

+0

UriTemp = String.Format ("http://twimlets.com/echo?Twiml=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22 % 3F % 3E % 0A % 3CResponse % 3E % 0A % 20 % 20 % 20 % 20 % 3CSay % 20 % 3D % 22 % % 22 % 20 % % 3D % 22en-gb % 22 % 3EHi % 20i % 20 % % 20calling % 20from % 20Service % 20Desk % 20A % 20M % 20S % 20Alert. % 20A % 20High % 20Priority % 20Inside % 20P % 20 {1} % 20has % 20been % 20raised % 20in % 20your % 20service % 20Service % 20name % 20is % 20 { 0}. % 20 % 3C % 2FSay % 3E % 0A % 3C % 2FResponse % 3E & ", servicename, Priority); – Ajith

+0

지연에 대해 사과드립니다. 그냥 따라 잡는거야. 이 코드 샘플에서와 같이 "URL"매개 변수와 해당 값을 추가하여 url을 보낼 수 있습니다 :'var result = httpClient.PostAsync (callUrl, new FormUrlEncodedContent (new Dictionary { { ("URL", "LINK_TO_TWIML_URL"})); 다음은 [문서 링크]입니다/api/voice/making-calls # post-parameters)를 사용하여 게시 할 수있는 다른 매개 변수를 나열합니다. –