Yon
Yon

Reputation: 31

Indy HTTP only sending numbers and stops at letters

I'm using Indy with Lazarus

Here is my code:

IdHTTP1.Request.ContentType  := 'text/plain' ;
IdHTTP1.Response.ContentType :=  'text/plain' ;
IdHTTP1.Response.Charset :=  'ISO-8859-1,utf-8;q=0.7,*;q=0.3'   ;
IdHTTP1.Request.CharSet:=    'ISO-8859-1,utf-8;q=0.7,*;q=0.3 '  ;
IdHTTP1.HTTPOptions := IdHTTP1.HTTPOptions + [hoNoProtocolErrorException];      
IdHTTP1.Get('http://192.168.25.965:8541/rest/SearchCard('+MYCARD+')',Stream)  ; 

If I start MYCARD with a letter, the server is picking up the full string. However, if I start with a number, it stops at the first letter.

MYCARD:= '12366854';     //works 

MYCARD:= 'A125ASD555';   //Works 

MYCARD:= '123YH963';   // The server only sees 123 

What am I doing wrong?

Upvotes: 0

Views: 126

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597941

First off, the two Request properties you are setting are meaningless in a GET request, and you should not be setting any Response properties at all.

// get rid of these assignments
//IdHTTP1.Request.ContentType  := 'text/plain' ;
//IdHTTP1.Response.ContentType :=  'text/plain' ;
//IdHTTP1.Response.Charset :=  'ISO-8859-1,utf-8;q=0.7,*;q=0.3'   ;
//IdHTTP1.Request.CharSet:=    'ISO-8859-1,utf-8;q=0.7,*;q=0.3 '  ;

IdHTTP1.HTTPOptions := IdHTTP1.HTTPOptions + [hoNoProtocolErrorException];      
IdHTTP1.Get('http://192.168.25.965:8541/rest/SearchCard('+MYCARD+')', Stream); 

Second, using the current version of Indy, I cannot reproduce your issue. TIdHTTP.Get() sends the specified URL as-is, it makes no assumptions about the characters in it (you are responsible for URL encoding). In my testing, 123YH963 works just fine. Here is the actual HTP request being sent:

GET /rest/SearchCard(123YH963) HTTP/1.1
Host: 192.168.25.965:8541
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
User-Agent: Mozilla/3.0 (compatible; Indy Library)

As you can see, the full MYCARD text is in the requested resource, as expected. So any truncation must be happening on the server side, not in TIdHTTP itself.

Are you sure you are formatting the URL correctly to begin with? Are you sure it should actually be sent like this:

/rest/SearchCard(123YH963)

And not something more like these instead?

/rest/SearchCard%28123YH963%29

/rest/SearchCard/123YH963

/rest/SearchCard?param=123YH963

Upvotes: 3

Related Questions