Trying your HTTPClient

Topics: Question
Sep 22, 2016 at 1:38 PM
Edited Sep 22, 2016 at 2:12 PM
Hello Julius,

we didn't hear a Long time, sorry I was very busy :-)

I hope you are well!

I am still using the older Version of the rtp Client, didn't have the time to try the new one, sorry.
but it works good with the older one, too.

One question please:

I have to add some web requests to my app. I have Problems with Android when I am using the System.Net.Httpclient there. A fallback with System.Net.WebRequest has the same Problems.

On iOS it works fine, on Android it works sometimes, but other times it does strange stuff like changing the endpoint etc when Requests are sent.

So I would like to try your HTTPclient, because your stuff works good :-)

I start with a string uri, a username and a Password. The uri Looks like this

"http://192.168.1.106:8080/login/user/call_log_list.cgi"

The username and password are used for credentials.

I try to return into a HttpResponseMessage, because the old function did use it and I do not want to Change all the calling functions.

Right now as Response I get a "Bad Request", I think I messed up the pieces of the uri...

So I try with your class, I am not sure which part belongs to the Parameter in the new httpClient and which part exactly belongs :
        private static async Task<HttpResponseMessage> getAsyncTest(String uri, String username, String password)
        {
            Uri u = new Uri(uri);

            using (Media.Http.HttpClient httpClient = new Media.Http.HttpClient("http://"+u.Authority))
            {
                httpClient.Credential = new NetworkCredential(username, password);

                using (Media.Http.HttpMessage httpMessage = new Media.Http.HttpMessage(Media.Http.HttpMessageType.Request))
                {

                    httpMessage.MethodString = u.AbsolutePath;

                    try
                    {
                        System.Net.Sockets.SocketError error;

                        bool useClientProtocolVersion = false, hasResponse = true;

                        int maxAttempts = 0;

                      //needed? configureHttpClient(httpClient);


                      //needed? configureHttpMessage(httpMessage);

                        //
                        //needed? httpClient.ProtocolVersion = 1.1;

                        //
                        //if (useClientProtocolVersion.Equals(false))
                        //{
                        //    httpMessage.Version = 1.2;
                        //}

                        using (Media.Http.HttpMessage httpResponse = httpClient.SendHttpMessage(httpMessage, out error, useClientProtocolVersion, hasResponse, maxAttempts))
                        {
                            var response = new HttpResponseMessage(HttpStatusCode.OK);
                            response.Content = new StringContent(httpResponse.Body);
                            return response;
                        }
                    }
                    catch (Exception @_)
                    {
                        return null;
                    }
                    finally
                    {
                      Media.Common.Extensions.Debug.DebugExtensions.BreakIfAttached();
                    }
                }
            }
        }
Sep 22, 2016 at 2:28 PM
Edited Sep 22, 2016 at 2:36 PM
The Error is

{HTTP/1.1 400 Bad Request

Content-Type: text/html; charset=us-ascii
Server: Mono-HTTPAPI/1.0
Date: Thu, 01 Jan 1970 00:01:56 GMT
Content-Length: 37
Connection: close
<h1>Bad Request ((Invalid verb))</h1>}

The date Problem on the Server is known. ;-)

I also tried with

useClientProtocolVersion = true
int maxAttempts = 3;

I guess the problem is the strings in

new Media.Http.HttpClient("http://" + u.Authority))
which is
http://192.168.1.106:8080

or
using (Media.Http.HttpMessage httpMessage = new Media.Http.HttpMessage(Media.Http.HttpMessageType.Request))
which is
{/login/user/call_log_list.cgi * HTTP/1.1

}
this way, I do not know, how to feed them correctly, could you give me a hint?

Thanks!
Sep 22, 2016 at 2:36 PM
I tried with adding the whole uri
"http://192.168.1.106:8080/login/user/call_log_list.cgi"
using (Media.Http.HttpClient httpClient = new Media.Http.HttpClient(uri))
...

and did not set the httpMessage.MethodString or Version anymore, I get:

{HTTP/1.1 400 Bad Request

Content-Type: text/html; charset=us-ascii
Server: Mono-HTTPAPI/1.0
Date: Thu, 01 Jan 1970 00:12:53 GMT
Content-Length: 62
Connection: close
<h1>Bad Request (Invalid url: http://192.168.1.109:8080*)</h1>}
Coordinator
Sep 22, 2016 at 4:48 PM
Contact ASTI if you need help with this Software.

L8r
Marked as answer by juliusfriedman on 9/22/2016 at 9:50 AM