Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Hi,
I try to connect to server thro ISocket connection. It works fine.But when i try to go read another page it reads info from default location. For ex. i have connectivity with
http://wap.openmotion.com/ypc/midpypc.It reads from that page. But when i make connection to http://wap.openmotion.com/ypc/midpypc?cmd=8[1], it reads info from http://wap.openmotion.com/ypc/midpypc.
Why this happen? any idea could be helpful.
Thanks in advace.
B.Sugu

Your query string contains reserved characters (the square brackets) that need to be URL encoded. See IWebUtil_UrlEncode() for more details. Basically, your request needs to end up looking something like this:
GET /ypc/midpypc?cmd=8%5B1%5D HTTP/1.0
P.S. consider using IWeb instead of ISocket; it handles many, many details for you.

Your query string contains reserved characters (the square brackets) that need to be URL encoded. See IWebUtil_UrlEncode() for more details. Basically, your request needs to end up looking something like this:
GET /ypc/midpypc?cmd=8%5B1%5D HTTP/1.0
P.S. consider using IWeb instead of ISocket; it handles many, many details for you.

if you use IWebUtil_UrlEncode(), make sure to only use it on the "end" of the url.. not the whole thing.. so for your example url:
http://wap.openmotion.com/ypc/midpypc?cmd=8[1]
only use IWebUtil_UrlEncode() on the part following the last /:
midpypc?cmd=8[1]
This is written in the API doc but most people miss it the first time around.
-Tyndal

if you use IWebUtil_UrlEncode(), make sure to only use it on the "end" of the url.. not the whole thing.. so for your example url:
http://wap.openmotion.com/ypc/midpypc?cmd=8[1]
only use IWebUtil_UrlEncode() on the part following the last /:
midpypc?cmd=8[1]
This is written in the API doc but most people miss it the first time around.
-Tyndal

Thanks Kurquhar and tyndal.
I try to send the special char thro' like this.
SPRINTF(Request,"GET %s 8%5B1%5D HTTP/1.0\r\n\r\n", pMe->UrlLink);
iRet = ISOCKET_Write(pMe->m_piSock, (byte*)Request, (uint16)STRLEN(Request));
But Request has the value of URL link as GET http://wap.openmotion.com/ypc/midpypc?cmd=8[1] 8 http://wap.openmotion.com/ypc/midpypc?cmd=8[1] D HTTO/1.0 and still reads info from http://wap.openmotion.com/ypc/midpypc.
How to ensure that BREW to read from specied URL?

Thanks Kurquhar and tyndal.
I try to send the special char thro' like this.
SPRINTF(Request,"GET %s 8%5B1%5D HTTP/1.0\r\n\r\n", pMe->UrlLink);
iRet = ISOCKET_Write(pMe->m_piSock, (byte*)Request, (uint16)STRLEN(Request));
But Request has the value of URL link as GET http://wap.openmotion.com/ypc/midpypc?cmd=8[1] 8 http://wap.openmotion.com/ypc/midpypc?cmd=8[1] D HTTO/1.0 and still reads info from http://wap.openmotion.com/ypc/midpypc.
How to ensure that BREW to read from specied URL?

Assuming that pMe->UrlLink contains "/ypc/midpypc", the format string in SPRINTF() needs to be "GET %s?cmd=8%5B1%5D HTTP/1.0\r\n\r\n".

Assuming that pMe->UrlLink contains "/ypc/midpypc", the format string in SPRINTF() needs to be "GET %s?cmd=8%5B1%5D HTTP/1.0\r\n\r\n".

i tried to pass that too..i make pMe->UrlLink with main directory and rest thr' sprinf(). but all possibilites failed.
encoding url works for anyone? or how to ensure to work?
can i use IWEBUTIL_UrlEncode along with isocket?

i tried to pass that too..i make pMe->UrlLink with main directory and rest thr' sprinf(). but all possibilites failed.
encoding url works for anyone? or how to ensure to work?
can i use IWEBUTIL_UrlEncode along with isocket?

SPRINTF(Request, "GET %s?cmd=8%5B1%5D HTTP/1.0\r\n\r\n", pMe->UrlLink);
looks like the percent signs are causing the problems.. normally you would escape them with another percent so %% would get you a literal percent.. but the BREW SPRINTF function doesnt seem to support that..
Looks like you need to use IWEBUTIL_EncodeUrl() on everything after the ? in your url string.
here is a sample function to do what you need
void encodeTest(Sample * pApp)
{
char Request[90];
char decode[90];
char encode[90];
char url[90];
IWebUtil * pWebUtil;
int enclen=0, declen=0;
MEMSET(encode, 0, sizeof(encode));
SPRINTF(url, "http://wap.openmotion.com/ypc/midpypc?");
SPRINTF(decode,"cmd=8[1]");
// need to add error checking
ISHELL_CreateInstance(pApp->pShell, AEECLSID_WEBUTIL, (void **)&pWebUtil);
declen = STRLEN(decode);
enclen = sizeof(encode);
IWEBUTIL_UrlEncode(pWebUtil, decode, &declen, encode, &enclen);
SPRINTF(Request,"GET %s%s HTTP/1.0\r\n\r\n", url, encode);
DBGPRINTF(url);
DBGPRINTF(decode);
DBGPRINTF(encode);
// dbgprintf doesnt display the % chars, but they are in there
DBGPRINTF(Request);
// free webutil when you are done
IWEBUTIL_Release(pWebUtil);

SPRINTF(Request, "GET %s?cmd=8%5B1%5D HTTP/1.0\r\n\r\n", pMe->UrlLink);
looks like the percent signs are causing the problems.. normally you would escape them with another percent so %% would get you a literal percent.. but the BREW SPRINTF function doesnt seem to support that..
Looks like you need to use IWEBUTIL_EncodeUrl() on everything after the ? in your url string.
here is a sample function to do what you need
void encodeTest(Sample * pApp)
{
char Request[90];
char decode[90];
char encode[90];
char url[90];
IWebUtil * pWebUtil;
int enclen=0, declen=0;
MEMSET(encode, 0, sizeof(encode));
SPRINTF(url, "http://wap.openmotion.com/ypc/midpypc?");
SPRINTF(decode,"cmd=8[1]");
// need to add error checking
ISHELL_CreateInstance(pApp->pShell, AEECLSID_WEBUTIL, (void **)&pWebUtil);
declen = STRLEN(decode);
enclen = sizeof(encode);
IWEBUTIL_UrlEncode(pWebUtil, decode, &declen, encode, &enclen);
SPRINTF(Request,"GET %s%s HTTP/1.0\r\n\r\n", url, encode);
DBGPRINTF(url);
DBGPRINTF(decode);
DBGPRINTF(encode);
// dbgprintf doesnt display the % chars, but they are in there
DBGPRINTF(Request);
// free webutil when you are done
IWEBUTIL_Release(pWebUtil);

thank you very much tyndal.
IwebUtil_encode does the same thing what we try to hard code for the spl chars.But even after we send encoded URL, it still reads from default location not from http://wap.openmotion.com/ypc/midpypc?cmd=8[2]. I put my code for you to check if i do anything wrong..
char Request[90];
char decode[90];
char encode[90];
char url[90];
IWebUtil * pWebUtil;
int enclen=0, declen=0;
pMe->bytecount=0;
// if connection is made
Status(pMe,"Connected");
{
int Ret;
if(pMe->UrlLink != NULL)
MEMSET(encode, 0, sizeof(encode));
SPRINTF(url, "http://wap.openmotion.com/ypc/midpypc?");
SPRINTF(decode,"cmd=8[2]");
// need to add error checking
ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEBUTIL, (void **)&pWebUtil);
declen = STRLEN(decode);
enclen = sizeof(encode);
IWEBUTIL_UrlEncode(pWebUtil, decode, &declen, ncode,&enclen);
SPRINTF(Request,"GET %s%s HTTP/1.0\r\n\r\n", url, encode);
DBGPRINTF(url);
DBGPRINTF(decode);
DBGPRINTF(encode);
// dbgprintf doesnt display the % chars, but they are in there
DBGPRINTF(Request);
Ret = ISOCKET_Write(pMe->m_piSock, (byte*)Request, (uint16)STRLEN(Request));

Socket_ReadSocket(pMe);

thank you very much tyndal.
IwebUtil_encode does the same thing what we try to hard code for the spl chars.But even after we send encoded URL, it still reads from default location not from http://wap.openmotion.com/ypc/midpypc?cmd=8[2]. I put my code for you to check if i do anything wrong..
char Request[90];
char decode[90];
char encode[90];
char url[90];
IWebUtil * pWebUtil;
int enclen=0, declen=0;
pMe->bytecount=0;
// if connection is made
Status(pMe,"Connected");
{
int Ret;
if(pMe->UrlLink != NULL)
MEMSET(encode, 0, sizeof(encode));
SPRINTF(url, "http://wap.openmotion.com/ypc/midpypc?");
SPRINTF(decode,"cmd=8[2]");
// need to add error checking
ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_WEBUTIL, (void **)&pWebUtil);
declen = STRLEN(decode);
enclen = sizeof(encode);
IWEBUTIL_UrlEncode(pWebUtil, decode, &declen, ncode,&enclen);
SPRINTF(Request,"GET %s%s HTTP/1.0\r\n\r\n", url, encode);
DBGPRINTF(url);
DBGPRINTF(decode);
DBGPRINTF(encode);
// dbgprintf doesnt display the % chars, but they are in there
DBGPRINTF(Request);
Ret = ISOCKET_Write(pMe->m_piSock, (byte*)Request, (uint16)STRLEN(Request));

Socket_ReadSocket(pMe);

Check your server logs, are you sure it is requesting the correct/incorrect url?
Is the string you are trying to use going out of scope?
Does it work if you use the IWeb interface instead of ISocket?
Also, i just checked using wget and a web browser, and
http://wap.openmotion.com/ypc/midpypc
http://wap.openmotion.com/ypc/midpypc?cmd=8%5B1%5D
http://wap.openmotion.com/ypc/midpypc?cmd=8%5B2%5D
all result in the same output.. could that be your problem.. the server is sending the wrong result?
-Tyndal

Check your server logs, are you sure it is requesting the correct/incorrect url?
Is the string you are trying to use going out of scope?
Does it work if you use the IWeb interface instead of ISocket?
Also, i just checked using wget and a web browser, and
http://wap.openmotion.com/ypc/midpypc
http://wap.openmotion.com/ypc/midpypc?cmd=8%5B1%5D
http://wap.openmotion.com/ypc/midpypc?cmd=8%5B2%5D
all result in the same output.. could that be your problem.. the server is sending the wrong result?
-Tyndal

URL is correct and it works well in Browser. URL gives problem only when it has [] . I tried IWeb thro sample app, it also gives the problem.

URL is correct and it works well in Browser. URL gives problem only when it has [] . I tried IWeb thro sample app, it also gives the problem.

so your server logs say you are requesting
/ypc/midpypc?cmd=8%5B1%5D
but you are getting data the corresponds to another url?
the data corresponds to which url?
this one?
ypc/midpypc

so your server logs say you are requesting
/ypc/midpypc?cmd=8%5B1%5D
but you are getting data the corresponds to another url?
the data corresponds to which url?
this one?
ypc/midpypc

Well, I use wget, browser, and even telnet directly to that server, and i get the same response for
GET /ypc/midpypc?cmd=8%5B1%5D HTTP/1.0
GET /ypc/midpypc?cmd=8%5B2%5D HTTP/1.0
GET /ypc/midpypc HTTP/1.0
are they supposed to be different responses?
I think it is a problem with your server.

Well, I use wget, browser, and even telnet directly to that server, and i get the same response for
GET /ypc/midpypc?cmd=8%5B1%5D HTTP/1.0
GET /ypc/midpypc?cmd=8%5B2%5D HTTP/1.0
GET /ypc/midpypc HTTP/1.0
are they supposed to be different responses?
I think it is a problem with your server.

Yes. each URL points to different page. URLs work well in Browser..if there is any problem in the server side, it wont work in browser too.

Yes. each URL points to different page. URLs work well in Browser..if there is any problem in the server side, it wont work in browser too.

No, thats what i am saying, all 3 of those urls get the same results for me when using a browser.. (mozilla v5.1), telnet, and wget (v1.9.1)
this is the result i am getting:
M,Mobile Yellow Pages,Business Search;Category Search;Distance Search;Zip Code Search;Area Code Search;Search Options,Select=8;Quit=7

No, thats what i am saying, all 3 of those urls get the same results for me when using a browser.. (mozilla v5.1), telnet, and wget (v1.9.1)
this is the result i am getting:
M,Mobile Yellow Pages,Business Search;Category Search;Distance Search;Zip Code Search;Area Code Search;Search Options,Select=8;Quit=7

ok, here might be your problem..
If i use IE and go to url:
http://wap.openmotion.com/ypc/midpypc?cmd=8%5B2%5D
i get the result
M,Mobile Yellow Pages,Business Search;Category Search;Distance Search;Zip Code Search;Area Code Search;Search Options,Select=8;Quit=7
But if i go to the url:
http://wap.openmotion.com/ypc/midpypc?cmd=8[2]
i get the result:
M,Distance Search,By Category;By Business Name,Select=8;Home=1;Back=2
so IE is getting different responses.. maybe IE is using HTTP/1.1 ?? .. anyway since your client is obviously not IE, try your testing by telneting into your server and sending the GET requests.. and fix your server to match the output you are expecting..
otherwise use a net sniffer to try and find out the differences of your IE request and a direct request when telnetting in.

ok, here might be your problem..
If i use IE and go to url:
http://wap.openmotion.com/ypc/midpypc?cmd=8%5B2%5D
i get the result
M,Mobile Yellow Pages,Business Search;Category Search;Distance Search;Zip Code Search;Area Code Search;Search Options,Select=8;Quit=7
But if i go to the url:
http://wap.openmotion.com/ypc/midpypc?cmd=8[2]
i get the result:
M,Distance Search,By Category;By Business Name,Select=8;Home=1;Back=2
so IE is getting different responses.. maybe IE is using HTTP/1.1 ?? .. anyway since your client is obviously not IE, try your testing by telneting into your server and sending the GET requests.. and fix your server to match the output you are expecting..
otherwise use a net sniffer to try and find out the differences of your IE request and a direct request when telnetting in.

Yes..I checked from other m/c too..It gives different result in different m/c ..Server may be problem..i hv to ask my(US) client to restart the server and then check my application. Hope that may solve my problem.
I can use IWEBUTIL_UrlEncode along with ISocket. Thanks for your HELP.

Yes..I checked from other m/c too..It gives different result in different m/c ..Server may be problem..i hv to ask my(US) client to restart the server and then check my application. Hope that may solve my problem.
I can use IWEBUTIL_UrlEncode along with ISocket. Thanks for your HELP.

You can pass URL in special char as Request. ISocket_Write can able to understand the request.We dont need to encode them.

You can pass URL in special char as Request. ISocket_Write can able to understand the request.We dont need to encode them.