Question

I am trying to use Plivo to send text messages from within my WindowsStore Application. Here is what almost works:

// These first 3 lines don't do what I want
var unamepass = AuthID + ":" + AuthToken;
var auth = new HttpCredentialsHeaderValue("Basic", unamepass);
httpClient.DefaultRequestHeaders.Authorization = auth;

string textBody = "sample message";
var plivoText = new
{
    src = plivoNumber,
    dst = phoneNumber,
    text = textBody
};
string Serial = JsonConvert.SerializeObject(plivoText);
IHttpContent PlivoJsonContent = new HttpJsonContent(JsonValue.Parse(Serial));
HttpResponseMessage PlivoResponse = 
    await httpClient.PostAsync(
        new Uri("https://api.plivo.com/v1/Account/<AuthID>/Message/")
        , PlivoJsonContent);

Now, this code works... technically. I get a 202 response back. However, before it sends the text, a large authentication pops onto the screen.enter image description here

If I enter the correct data I get a 202 and the text sends, otherwise I can't send the data. I want to know how to programmatically add this to the request, so I don't have to do it manually. I'm pretty sure it has something to do with the first 3 lines of the snippet, but the documentation I found online wasn't very helpful to me. I can't use RestSharp because it isn't supported for windows store projects, so I would prefer an HttpClient solution.

What "scheme" does Plivo use? How should I construct HttpCredentialsHeaderValue? Is the 3rd line correct?

Was it helpful?

Solution

The answer was startlingly simple. You must convert the string to base64 in order to send it to the header.

See: Convert UTF-8 to base64 string

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top