The powerful iweb interface

Source: Internet
Author: User
Tags reserved iweb

Overview

This article focuses on the Iweb interface introduced in 1.1SDK, and the related Iwebresp, iwebopt, Iwebutil and other API usage methods. It also includes the functionality of each API and interaction with other APIs, such as Ihtmlviewer.

―――――――――――――――――――――――――――――――――――――――

Basic Role

In brew applications, the Iweb interface is primarily used to initiate HTTP requests. In an HTTP request, you can either get the file through "getting" or upload the data through "POST", both of which are supported by iweb. Iweb manages its own connections and sockets, so it is more conducive to network transmission.

The Iweb_getpesponse function is used to start the network transport.

Void Iweb_getresponse (

Iweb * Piweb,

IWEBRESP * * Ppiwresp,

Aeecallback * PCB,

Const char * cpszurl,

...

)

which

Piweb a valid pointer to an instantiated iweb object.

Ppiwresp a valid pointer to the IWEBRESP pointer.

The PCB points to a valid pointer to an instantiated Aeecallback object.

Cpszurl A pointer to a URL.

... is the name and value of the items in the webopt, aligned in pairs, ending with webopt_end.

Note: IWEBRESP pointers cannot be created in the stack. In order to ensure that it is valid throughout the callback process, it is better to create the corresponding structure in the application.

The URL may not contain any reserved characters. If it must be included, be aware of the conversion. See the "using reserved characters in URLs" section of this article.

The simplest form of requesting a file in iweb is as follows:

Create IWeb Instance

Ishell_createinstance (Pme->a.m_pishell,aeeclsid_web, (viod**) &pme->m_piweb);

Initialize the callback to WEBREADCB

Callback_init (&PME->M_CALLBACK,WEBREADCB,PME);

Request IWEB to fetch the URL

Iweb_cetresponse (Pme->m_piweb, pme->m_piweb,&pme->m_piwebresp,&pme->m_callback,http:// Www.qualcomm.com,WEBOPT_END));

note the special syntax passed by parameters in this function.

Iweb and the server-side URL "www.qualcomm.com" Establish a network connection and request a file. When the iweb engine obtains a response from the server, it passes through the PCB to the callback function in Aeecallback. If the file is requested in a way that is not specified, the default is "get". How to request a file and how to set up other options, see "Webopts settings in the Iweb_getresponse request" in this article.

The Webrespinfo structure Body contains the response message body and other related information (such as error number, length, type, etc.), so the Iweb_getinfo function can be used to parse webrespinfo get the content of the response. See the "How to understand the error number in Webrespinfo" section of this article.

Callback

static void Webreadcb (void * cxt)

{

...

Get information about the response

Webrespinfo * Pwebrespinfo = Iwebresp_getinfo (PME->M_PWEBRESP);

The body of the response are contained in the ISOURCE

ISource * Pisource = pwebrespinfo->pismesssage;

}

―――――――――――――――――――――――――――――――――――――――

Iweb_getresponse webopts settings in the request

Earlier, we've learned about using iweb to start a simple HTTP transmission, and now learn more about the Iweb interface by learning how webopts is used.

A webopt contains two things: the option name and its value. These webopt should be added to the Iweb_getresponse function to configure the request that will be issued. Webopt can be added in two ways:

using iweb_addopt

The options added in this way are permanent-this setting is valid as long as the Iweb object is not freed.

int i = 0;

Webopt AWO[10];

ADD handler Data

Awo[i].nid = Webopt_handlerdata;

Awo[i].nval = (void*) pMe;

i++;

Add the handler function for status callbacks

Awo[i].nid = Webopt_statushandler;

Awo[i].nval = (void*) webstatusnotification;

i++;

Add the option stating which method

Awo[i].nid = Webopt_method;

Awo[i].nval = (void*) "Get";

i++;

Marks the end of the arrary of webopts

Awo[i].nid = Webopt_end;

Add options

Iweb_addopt (PAPP->M_PIWEB,AWO);

Iweb_getresponse (Pme->m_piweb, Pme->m_piweb,&pme->m_piwebresp,&pme->m_callback, "thhp:// Webber.qualcomm.com ", webopt_end));

Add directly

The WEBOPT option name and value can be set directly in the Iweb_getresponse function:

Iweb_getresponse (Pme->m_piweb, Pme->m_piweb,&pme->m_piwebresp,&pme->m_callback, "http:// Webber.qualcomm.com ",

WEBOPT_HANDLERDATA,PME,

Webopt_statushandler,webstatusnotification,

Webopt_method, "get",

Webopt_end));

The settings added in this way are valid only in this iweb_getresponse.

Note: the requested settings should remain in effect throughout the callback, regardless of the manner in which they are added. Add webopt_copyopts to the options column if you want the settings to be automatically copied to the desired location.

Sometimes, the explanations in the AEEWeb.h file are more detailed than those in the API help. The usual weboptions and explanations are as follows:

Webopt_method: Set to use "get" or "POST" mode.

Take value: Get, POST.

webopt_body: The message body used to set up the post.

webopt_connecttimeout: Sets the time that iweb will need to wait in the process of trying to establish a connection successfully. When the time is up, the connection is discarded and the connection error number is returned. In milliseconds, the default value is the Aeenet connection length. A set of 0 indicates that the system defaults are used, and-1 indicates infinity. This value should be sufficient for a successful connection. Assuming the connection is successful, the server response is slow, and IWeb is not allowed to report a "connection timeout" during this process. You can use Ishell_settimer as needed.

webopt_idleconntimeout: The time at which an idle connection is maintained, and the connection is closed. The default value is the connection time of PPP in Inetmgr, set to 1 to indicate infinity.

Web_header: Sets up a special HTTP message header, composed of CRLF. CRLF refers to names and values that are listed separately, such as "name1:v1/r/nname2:v2/r/n".

Webopt_proxyspec : used to set up a proxy. See "Brewwebproxyspecknowledgebase" for details.

Webopt_flags : This setting affects the behavior of the underlying protocol engine. These flags enable us to gain more control over the use of the connection. The implemented flags are as follows:

Webrequest_nokeepalive:iweb will not deliberately stay connected. Releases the connection immediately after the data exchange has ended. By default, Iweb tries to stay connected.

Webrequest_forcenewconn: After a connection has been established with a server, iweb will re-establish a connection each time the server is connected, rather than the previous connection. In doing so, you will assume the following risks: There is no free socket available on the phone and the transfer fails. By default, iweb will reuse existing connections.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.