How to visit www.msn.com by IWeb? | developer.brewmp.com How to visit www.msn.com by IWeb? | developer.brewmp.com

Developer

How to visit www.msn.com by IWeb?

Forums:

I send URL request by IWEB_GetResponseV(), URL is msn.com, which WebOpt had been set ok.

BrwHttp_WebGotResp() can get the pstWebRespInfo->nCode is 400(protocol code equal define G_HTTP_BAD_REQUEST) and receive webpage content as below:

HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Fri, 26 Jan 2007 05:03:11 GMT
nnCoection: close
Content-Length: 42

Bad Request (Invalid Header Name)

So the request failure.

When I get network data packet by Ethereal tool I can get info as below:

GET / HTTP/1.1
Host: msn.com
User-Agent: BREW-Applet/0xEF765234 (BREW/3.1.5.27; DeviceId: 100001; Lang: en)
Connection: Keep-Alive
Accept: text/html, application/xhtml+xml; profile=http://www.wapforum.org/xhtml, application/vnd.wap.xhtml+xml, application/vnd.wap.wmlscriptc, application/vnd.wap.wmlc, text/vnd.wap.wml, application/octet-stream, text/plainimage/gif, image/bmp, image/jpeg, image/vnd.wap.wbmp, */*
Accept-Charset: utf-8, iso-8859-1, *
Accept-Language: en
User-Agent: Mozilla/5.0 (TechSoft/1.0) Profile/MIDP-2.0 Configuration/CLDC-1.1

From the info we can see, the IWeb's User-Agent be appended automatic by BREW that reflect on webpage content is Bad Request (Invalid Header Name) .

I want to use my Ueser-Agent(Mozilla/5.0 (TechSoft/1.0) Profile/MIDP-2.0 Configuration/CLDC-1.1).

So my question is how to cancel BREW's User-Agent(BREW-Applet/0xEF765234 (BREW/3.1.5.27; DeviceId: 100001; Lang: en) ) item?

Thanks!!!

construct your own http headers using sockets

construct your own http headers using sockets

You can try this.
WEBOPT_HEADER is the option which is
(char *) CRLF-separated, name-value pairs like this: "Name1: val\r\nName2: val\r\n",
defaults to NULL

You can try this.
WEBOPT_HEADER is the option which is
(char *) CRLF-separated, name-value pairs like this: "Name1: val\r\nName2: val\r\n",
defaults to NULL

bru wrote:You can try this.
WEBOPT_HEADER is the option which is
(char *) CRLF-separated, name-value pairs like this: "Name1: val\r\nName2: val\r\n",
defaults to NULL
WEBOPT_HEADER default to NULL the msn.com visited normally.
But I want to cancel BREW's User-Agent item, use my User-Agent item , when I send request.
I don't know how to do?
Thanks!!!

bru wrote:You can try this.
WEBOPT_HEADER is the option which is
(char *) CRLF-separated, name-value pairs like this: "Name1: val\r\nName2: val\r\n",
defaults to NULL
WEBOPT_HEADER default to NULL the msn.com visited normally.
But I want to cancel BREW's User-Agent item, use my User-Agent item , when I send request.
I don't know how to do?
Thanks!!!

Instead of
User-Agent: BREW-Applet/0xEF765234 (BREW/3.1.5.27; DeviceId: 100001; Lang: en)
give
User-Agent: Mozilla/5.0 (TechSoft/1.0) Profile/MIDP-2.0 Configuration/CLDC-1.1
If this is what you want to set, but not sure why are you using MIDP,CLDC which is for J2ME? I dont see any difference between BREW UA and J2ME UA.
Try using WEBOPT_HEADER(dont leave it to NULL). like
WEBOPT_HEADER,"User-Agent: Mozilla/5.0 (TechSoft/1.0) Profile/MIDP-2.0 Configuration/CLDC-1.1"
Many people already able to browse different site.
Simply if you try NetDiagnostics, and enter any site and see if you get response. Thats going to be the same behaviour in you app also.
The reason may be there will be some proxy setup on your network which wont allow you to connect to that site. But when you try the same in the handset, then you should be seeing rightway.

Instead of
User-Agent: BREW-Applet/0xEF765234 (BREW/3.1.5.27; DeviceId: 100001; Lang: en)
give
User-Agent: Mozilla/5.0 (TechSoft/1.0) Profile/MIDP-2.0 Configuration/CLDC-1.1
If this is what you want to set, but not sure why are you using MIDP,CLDC which is for J2ME? I dont see any difference between BREW UA and J2ME UA.
Try using WEBOPT_HEADER(dont leave it to NULL). like
WEBOPT_HEADER,"User-Agent: Mozilla/5.0 (TechSoft/1.0) Profile/MIDP-2.0 Configuration/CLDC-1.1"
Many people already able to browse different site.
Simply if you try NetDiagnostics, and enter any site and see if you get response. Thats going to be the same behaviour in you app also.
The reason may be there will be some proxy setup on your network which wont allow you to connect to that site. But when you try the same in the handset, then you should be seeing rightway.

Me too, I want to open the webpage http://www.yahoo.com
but I cannot open it. So i try to find source in this Brew forum and
I find it already.
this is code for open webpage.
But I don't know how to use it.
So anyone help me.Please teach me how to use it Please!!!
Idon't know.how to call it - - -> Notify_CB( ?,?) <-- want for Example it please
static void Notify_CB( void* pvUser, HViewNotify* pNotify )
{
WebAction *pwa = (WebAction *)pvUser,
guambrew* pApp = pwa->pParent;
WebRespInfo *pwri;
switch( pNotify->code )
{
case HVN_REDRAW_SCREEN:
IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
IHTMLVIEWER_Redraw(pApp->pIHtml);
break;
case HVN_JUMP:
case HVN_SUBMIT:
STRCPY(pApp->m_pszURL, pNotify->u.jump.pszURL);
pwa->pszPostData = STRCHR(pApp->m_pszURL, 1);
// if there's post data, construct a stream for IWeb to consume
if ((char *)0 != pwa->pszPostData) {
*pwa->pszPostData = 0;
if (SUCCESS ==ISHELL_CreateInstance(pApp->a.m_pIShell,AEECLSID_SOURCEUTIL,(void **)&pApp->pISourceUtil)) {
ISOURCEUTIL_PeekFromMemory(pApp->pISourceUtil, pwa->pszPostData + 1,
STRLEN(pwa->pszPostData + 1), 0, 0,&pwa->pipPostData);
ISOURCEUTIL_Release(pApp->pISourceUtil);
}
}
if ((IPeek *)0 != pwa->pipPostData) {
IWEB_GetResponse(pApp->pIWeb,
(pApp->pIWeb, &pwa->piWResp, &pwa->cb, pszUrl,
WEBOPT_HANDLERDATA, pwa,
WEBOPT_HEADER, "X-Method: POST\r\n", /* for kicks */
WEBOPT_METHOD, "POST",
WEBOPT_BODY, pwa->pipPostData,
WEBOPT_CONTENTLENGTH, STRLEN(pwa->pszPostData + 1),
WEBOPT_END));
} else {
IWEB_GetResponse(pApp->pIWeb,
(pApp->pIWeb, &pwa->piWResp, &pwa->cb, pszUrl,
WEBOPT_HANDLERDATA, pwa,
WEBOPT_HEADER, "X-Method: GET\r\n",
WEBOPT_END));
}
pwri = IWEBRESP_GetInfo(pwa->piWResp);
if ((ISource *)0 != pwri->pisMessage) {
ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_SOURCEUTIL, (void **)&pApp->pISourceUtil);
if((ISourceUtil *)0 != pApp->pISourceUtil){
//Get HTML Source as Stream
IHTMLVIEWER_Reset(pApp->pIHtml);
ISOURCEUTIL_AStreamFromSource(pApp->pISourceUtil, pwri->pisMessage, &pApp->pIAStream);
IHTMLVIEWER_LoadStream(pApp->pIHtml, pApp->pIAStream);
IHTMLVIEWER_SetActive(pApp->pIHtml, TRUE);
if(pApp->pIAStream != NULL) ReleaseObj((void**)&pApp->pIAStream);
ISOURCEUTIL_Release(pApp->pISourceUtil);
}
}
break;
case HVN_DONE:
IHTMLVIEWER_SetRect(pApp->pIHtml, &pApp->m_rc);
IHTMLVIEWER_Redraw( pApp->pIHtml );
break;
}

Me too, I want to open the webpage http://www.yahoo.com
but I cannot open it. So i try to find source in this Brew forum and
I find it already.
this is code for open webpage.
But I don't know how to use it.
So anyone help me.Please teach me how to use it Please!!!
Idon't know.how to call it - - -> Notify_CB( ?,?) <-- want for Example it please
static void Notify_CB( void* pvUser, HViewNotify* pNotify )
{
WebAction *pwa = (WebAction *)pvUser,
guambrew* pApp = pwa->pParent;
WebRespInfo *pwri;
switch( pNotify->code )
{
case HVN_REDRAW_SCREEN:
IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
IHTMLVIEWER_Redraw(pApp->pIHtml);
break;
case HVN_JUMP:
case HVN_SUBMIT:
STRCPY(pApp->m_pszURL, pNotify->u.jump.pszURL);
pwa->pszPostData = STRCHR(pApp->m_pszURL, 1);
// if there's post data, construct a stream for IWeb to consume
if ((char *)0 != pwa->pszPostData) {
*pwa->pszPostData = 0;
if (SUCCESS ==ISHELL_CreateInstance(pApp->a.m_pIShell,AEECLSID_SOURCEUTIL,(void **)&pApp->pISourceUtil)) {
ISOURCEUTIL_PeekFromMemory(pApp->pISourceUtil, pwa->pszPostData + 1,
STRLEN(pwa->pszPostData + 1), 0, 0,&pwa->pipPostData);
ISOURCEUTIL_Release(pApp->pISourceUtil);
}
}
if ((IPeek *)0 != pwa->pipPostData) {
IWEB_GetResponse(pApp->pIWeb,
(pApp->pIWeb, &pwa->piWResp, &pwa->cb, pszUrl,
WEBOPT_HANDLERDATA, pwa,
WEBOPT_HEADER, "X-Method: POST\r\n", /* for kicks */
WEBOPT_METHOD, "POST",
WEBOPT_BODY, pwa->pipPostData,
WEBOPT_CONTENTLENGTH, STRLEN(pwa->pszPostData + 1),
WEBOPT_END));
} else {
IWEB_GetResponse(pApp->pIWeb,
(pApp->pIWeb, &pwa->piWResp, &pwa->cb, pszUrl,
WEBOPT_HANDLERDATA, pwa,
WEBOPT_HEADER, "X-Method: GET\r\n",
WEBOPT_END));
}
pwri = IWEBRESP_GetInfo(pwa->piWResp);
if ((ISource *)0 != pwri->pisMessage) {
ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_SOURCEUTIL, (void **)&pApp->pISourceUtil);
if((ISourceUtil *)0 != pApp->pISourceUtil){
//Get HTML Source as Stream
IHTMLVIEWER_Reset(pApp->pIHtml);
ISOURCEUTIL_AStreamFromSource(pApp->pISourceUtil, pwri->pisMessage, &pApp->pIAStream);
IHTMLVIEWER_LoadStream(pApp->pIHtml, pApp->pIAStream);
IHTMLVIEWER_SetActive(pApp->pIHtml, TRUE);
if(pApp->pIAStream != NULL) ReleaseObj((void**)&pApp->pIAStream);
ISOURCEUTIL_Release(pApp->pISourceUtil);
}
}
break;
case HVN_DONE:
IHTMLVIEWER_SetRect(pApp->pIHtml, &pApp->m_rc);
IHTMLVIEWER_Redraw( pApp->pIHtml );
break;
}