none
Alternative To HttpClient RRS feed

  • Question

  • Hi Experts,

    i want to send sms from androdi phone using it as a getway,

    there is a nice project  on

    http://www.codeproject.com/Articles/857539/SMS-Gateway-using-Android-Phone

    the send sms routine it as under

     private async void SendMessage()
            {
    
                if (string.IsNullOrEmpty(txtIPAddress.Text))
                {
                    MessageBox.Show("Please enter an IP address", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtIPAddress.Focus();
                    return;
                }
    
                if (string.IsNullOrEmpty(txtContact.Text) || string.IsNullOrEmpty(txtMessage.Text))
                {
                    MessageBox.Show("Please enter the contact name/number and the message", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtContact.Focus();
                    return;
                }
    
                try
                {
    
                    btnSendMessage.Enabled = false;
    
                    using (var client = new HttpClient())
                    {
    
                        string url = ConstructBaseUri();
                        client.BaseAddress = new Uri(url);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                        if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtPassword.Text))
                        {
                            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                                        "Basic",
                                         Convert.ToBase64String(
                                         ASCIIEncoding.ASCII.GetBytes(
                                         string.Format("{0}:{1}", txtUserName.Text, txtPassword.Text))));
                        }
    
    
                        var postData = new List<KeyValuePair<string, string>>();
                        postData.Add(new KeyValuePair<string, string>("to", txtContact.Text));
                        postData.Add(new KeyValuePair<string, string>("message", txtMessage.Text));
                        HttpContent content = new FormUrlEncodedContent(postData); 
    
                        HttpResponseMessage response = await client.PostAsync(MessagesUrlPath, content);
                        if (response.IsSuccessStatusCode)
                        {
                            PostMessageResponse result = await response.Content.ReadAsAsync<PostMessageResponse>();
                            if (result.IsSuccessful)
                            {
                                txtOutput.Clear();
                                AddToOutput(result.ToString());
                                AddToOutput("");
                            }
                            else
                            {
                                MessageBox.Show(result.Description, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show(response.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    btnSendMessage.Enabled = true;
                }
            }

    can some body help me to how to convert it as a browser command some thing like 

    http://sushil:san12345@192.168.0.102:35129/send.html?smsto=9423155724&smsbody=HOW+R+U&smstype=sms

    the above command can be used on ICECOLd Ulitimate SMS Getway

    Tuesday, July 28, 2015 2:38 PM

All replies

  • Hi Sushil Agarwal,

    As your issue is not related to WCF, I suggest you can ask this question in asp.net forum about web api.

    Best Regards,
    Vince Li

    Friday, July 31, 2015 8:33 AM