none
HttpClient.SendAsync with JSON request returns "ERROR: illegal password" RRS feed

  • Question

  • I have a console project to call a web API that accepts JSON and returns.  My Httpclient finds the address and then when I use sendasync it returns a 200 OK response.  However, whether the request is well formed JSON or just nonsense the content of the response is "ERROR: illegal password".  This happens with both sendasyncs in the code. My code is as follows.  Any insights into the problem?
        class Program
        {
            public static string _pmaddress01 = "http://99.99.99.999/aa/bb.php/";
            
            private static async void RunClient()
            {
                HttpClient client = new HttpClient();
                
                client.BaseAddress = new Uri(_pmaddress01);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                action_authenticate aa = new action_authenticate ();
                aa.action = "authenticate";
                aa.password = "xxx";
                aa.id = "xx";
    
                string jsonText = JsonConvert.SerializeObject(aa) + /*" CR LF"*/ "\r\n" /*+ Environment.NewLine*/;
                Console.WriteLine(jsonText);
                //string jsonText = "abcde";
    
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, jsonText);
                HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
                string s = response.Headers.ToString();
                response.EnsureSuccessStatusCode();
    
                String responseString = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseString);
                send_message sm = new send_message();
                sm.numb = "9999999999";
                sm.message = "Hello from VS";
    
                string jsonTextSM = JsonConvert.SerializeObject(sm) + "\r\n";
                //string jsonTextSM01 = "abcd";
                HttpRequestMessage requestSM = new HttpRequestMessage(HttpMethod.Get, jsonTextSM);
                HttpResponseMessage responseSM = await client.SendAsync(requestSM, HttpCompletionOption.ResponseHeadersRead);
                string sSM = responseSM.Headers.ToString();
                responseSM.EnsureSuccessStatusCode();
    
                String responseStringsm = await responseSM.Content.ReadAsStringAsync();
                Console.WriteLine(responseStringsm);
                } 
    
            static void Main(string[] args)
            {
                RunClient();
    
                Console.WriteLine("Hit ENTER to exit...");
                string s = Console.ReadLine();
            }
        }
    }

    • Moved by Bob Shen Wednesday, January 30, 2013 8:52 AM
    Tuesday, January 29, 2013 4:25 PM

Answers

All replies

  • Hi Kenneth,

    I would like to redirect you to appropriate forum for better responses.  


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Mulak Wednesday, January 30, 2013 2:17 PM
    Wednesday, January 30, 2013 8:51 AM
  • I have a console project to call a web API that accepts JSON and returns. My Httpclient finds the address and then when I use sendasync it returns a 200 OK response. However, whether the request is well formed JSON or just nonsense the content of the response is "ERROR: illegal password". This happens with both sendasyncs in the code. My code is as follows. Any insights into the problem?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using System.IO;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    
    namespace Temp02
    {
        public class action_authenticate
        {
            public string action {get; set;}
            public string password {get; set;}
            public string id { get; set; }
        }
    
        public class send_message
        {
            public string numb { get; set; }
            public string message { get; set; }
        }
    
        class Program
        {
            //public static string _pmaddress01 = "http://99.99.99.999/aaa/bbb.php?format=json";
    
            private static async void RunClient()
            {
                HttpClient client = new HttpClient();
                
                client.BaseAddress = new Uri(_pmaddress01);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                method_authenticate ma = new method_authenticate ();
                ma.action = "authenticate";
                ma.password = "password";
                ma.client_id = "999";
    
                string jsonText = JsonConvert.SerializeObject(ma) + Environment.NewLine;
                Console.WriteLine(jsonText);
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, jsonText);
               
                HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
                string s = response.Headers.ToString();
                response.EnsureSuccessStatusCode();
    
                String responseString = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseString);
                send_message sm = new send_message();
                sm.numb = "99999999999";
                sm.message = "Hello";
                string jsonTextSM = JsonConvert.SerializeObject(sm) + "\r\n";
                HttpRequestMessage requestSM = new HttpRequestMessage(HttpMethod.Get, jsonTextSM);
                HttpResponseMessage responseSM = await client.SendAsync(requestSM, HttpCompletionOption.ResponseHeadersRead);
                string sSM = responseSM.Headers.ToString();
                responseSM.EnsureSuccessStatusCode();
    
                String responseStringsm = await responseSM.Content.ReadAsStringAsync();
                Console.WriteLine(responseStringsm);
                client.Dispose();
                } 
    
            static void Main(string[] args)
            {
                RunClient();
    
                Console.WriteLine("Hit ENTER to exit...");
                string s = Console.ReadLine();
            }
        }
    }

    • Merged by Bob Shen Thursday, January 31, 2013 10:12 AM duplicate
    Wednesday, January 30, 2013 2:32 PM
  • Can you make a request that causes it to validate?  If so, can you post a sample of the request?  If not, it sounds like the target is borked.

    KeepMyIdentities, Your Key to Password Security. Available now on the Windows Store: http://apps.microsoft.com/webpdp/en-US/app/keepmyidentities/61a9f340-97ac-4666-beab-39f9246cb6fa

    Thursday, January 31, 2013 3:51 AM