Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am calling ExpertTexting Api for sending SMS but my get Method is working fine when i try to send message using post its show invalid paramenter. below is my post method

private static string BaseUrl = "https://www.experttexting.com/ExptRestApi/sms/json//Message/Send";
var data = "?username=" + username + "&password=" + password + "&api_key=" + apikey + "&from=" + from + "&to=" + to + "&text=" + text + "&type=text";

using (var client = new HttpClient())
{
var serializedProduct = JsonConvert.SerializeObject(data);
var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
response = await client.PostAsJsonAsync(BaseUrl, content);
}

What I have tried:

private static string BaseUrl = "https://www.experttexting.com/ExptRestApi/sms/json//Message/Send";
var data = "?username=" + username + "&password=" + password + "&api_key=" + apikey + "&from=" + from + "&to=" + to + "&text=" + text + "&type=text";

using (var client = new HttpClient())
{
var serializedProduct = JsonConvert.SerializeObject(data);
var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json");
response = await client.PostAsJsonAsync(BaseUrl, content);
}
Posted
Updated 24-Jan-17 10:49am
Comments
Afzaal Ahmad Zeeshan 24-Jan-17 14:51pm    
Then kindly check what kind or parameters are they expecting?
Richard MacCutchan 24-Jan-17 14:52pm    
Looks like you are sending an invalid parameter.

1 solution

You're mixing up multiple ways of sending data:
  • The data string contains application/x-www-form-urlencoded data:
    plain
    ?username=...&type=text
  • You then call JsonConvert.SerializeObject to convert that string to JSON:
    plain
    "?username=...&type=text"
  • You then call PostAsJsonAsync, which will JSON-encode the data again:
    plain
    "\"?username=...&type=text\""

You'll need to check with the API documentation to see how you are supposed to be passing the data. At a guess, it should look something like this:
C#
using (var client = new HttpClient())
{
    response = await client.PostAsJsonAsync(BaseUrl, new
    {
        username,
        password,
        api_key = apikey,
        from,
        to,
        text,
        type = "text"
    });
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900