Brew advanced and proficient-3G mobile value-added service operation, customization and development-74-HTTP development in brew

Source: Internet
Author: User
Tags iweb

The main purpose of the iWeb interface is to generate an HTTP request for the application. The file request uses the "get" method in HTTP, And the uploaded data is implemented through the "post" method in HTTP. IWeb can manage its own connections and sockets, and use the iweb_getresponse function to start a web access.

An example of a file requesting the Internet is as follows:

// Create iWeb instance

Ishell_createinstance (PME-> A. m_pishell, aeeclsid_web, (void **) & PME-> m_piweb );

// Initialize the callback to webreadcb

Callback_init (& PME-> m_callback, webreadcb, PME );

// Request iWeb to fetch the file

Iweb_getresponse (PME-> m_piweb,

(PME-> m_piweb, & PME-> m_piwebresp, & PME-> m_callback,

"Http://www.qualcomm.com", webopt_handlerdata, PME,

Webopt_statushandler, webstatusnotification,

Webopt_method, "get", webopt_end ));

Specifically, webreadcb () is the callback function for obtaining the server content. The implementation is as follows:

Static void webreadcb (void * cxt)

{

...

// Get information about the response

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

// The Body of the response is contained in the isource

Isource * pisource =Pwebrespinfo-> Pismessage;

}

Webopts (Web options) is used to operate on iWeb configuration options. Iwebopts indicates the option stack or list. These options can be single-value or multi-value, and do not have the semantics of Single-value or multi-value options. The access to the option stack is performed in the order of adding. You can set it through iwebopt or directly specify it in the Web request.

Pfnwebheader is a callback function prototype used to obtain HTTP header information. It will be passed to iweb_addopt () or iweb_getresponse () as webopt_headerhandler (). Pfnwebstatus is the callback prototype for obtaining the Request status. It is passed to iweb_addopt () or iweb_getresponse () as iwebopt_statushandler ().

If a URL contains some keywords, encode the URL first. Otherwise, the URL cannot be parsed correctly. The example is as follows:

// Determine what the length of the output buffer needs to be

Iwebutil_urlencode(PME-> m_piwebutil,

(Const char *) (BUF), // buffer containing the suffix of URL with reserved chars

& Ndatalen, // number of characters to be encoded

Null, // If null, method calculatessize of buffer needed

& PME-> m_dwcontentlength // contains the length of the buffer required

);

// Allocate space to hold the encoded string

If (PME-> m_dwcontentlength)

PME-> m_szdata = (char *) malloc (PME-> m_dwcontentlength); // encode the string.

Iwebutil_urlencode(PME-> m_piwebutil,

(Const char *) (BUF), & ndatalen, PME-> m_szdata, & PME-> m_dwcontentlength );

The iWeb interface can keep the HTTP connection active, which is the default status of the iWeb interface. You can disable this function by using the Web options webrequest_nokeepalive and webopt_flag. The persistence status depends on the HTTP header of Content-Length. This feature works normally only when the HTTP header of "Content-Length: XXX" is valid. For the remote end, if you need to know when to adjust the read time or when you need to know the content length, the connection must be closed.

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.