[转] What is HTTP POST? What is the land of Wu?

xiaoxiao2021-03-06  39

HTTP POST can actually speak each other. . . The user (Client) is reported to the server (for example, JSP, ASP, PHP, and other Scripting languages), then output certain preset answers. For more explanation, please read the RFC2616.pdf file; this file is very easy to search each other, especially the official website of W3C. Generally I 哋 喺 喺 个 ASP-ASP, JSP-JSP, or ASP-JSP web page communication program. . . . . . Do you think about the reference this program in a general desktop (DESKTOP) For example VB6 or VC 咁? For example; if a Win32 Application requires a user to verify the login interface, but the problem is often a large-purpose institution (server) that the database will have the user's data to log in to the password. The average person Answer: "Direct contact 嗰 database and read should be required to get the material ... Why do you get a trouble?" 啱, if a plan is limited to one institution; but in all Working in multiple institutions in the same location?喺咁 Do a generous, do you have a problem with safety? Maybe there may be: "Is there a VPN in the general institution ~" 啱, but there is a certain wave of many ways to achieve the expected effect. . . Some people will add: "It's better to use WebServices!" Answer; and I want to speak how to apply HTTP POST to do a user login verification function but you need to use WebServices technology (as shown below). Solution 喺 Use Wininet.dll to join the network API card; and I only need a few APIs to reach the user login to verify the function. InternetOpen InternetConnect HttpOpenRequest HttpAddRequestHeaders HttpSendRequest HttpQueryInfo InternetQueryDataAvailable InternetReadFile InternetCloseHandle be known as an API function to each of the generous a detailed explanation, see MSDN Library shall prevail. This experiment is divided into two parts: 1. ASP Script is used to verify the reporting data. 2. Win32 VC program is used to report data (HTTP POST) to the server. Because an ASP Script is very simple or even a clear, I will also explain more.

<

% @ Language

=

VBScript CodePage

=

65001

%

>

<

%

DIM

UserID

DIM

Password

DIM

Result

'

// Get The Current Posted Data

UserID

=

REQUEST.FORM

"

UserID

"

Password

=

REQUEST.FORM

"

Password

"

)

'

// Verify the userid & password

IF

Strcomp

(UserID,

"

admin

"

,

0

)

<>

0

THEN

Result

=

"

Invalid User ID! "

Elseif

Strcomp

(Password,

"

P @ SSW0RD

"

,

0

)

<>

0

THEN

Result

= "

INVALID Password! "

Else

Result

=

"

Logon Successful! "

end

IF

'

// Write the result

Response.write result

'

// Stop All Response

RESPONSE.

End

%

>

As for a VC source code, it is necessary to emphasize three items: one: INTERNETCONNECT second quotes will be a servo terminal IP or less URL; when you use this source code, be careful. Remember to be changed (if you serve the same computer with the same development platform, 127.0.0.1 also represents localhost). Second: HTTPOPENREQUEST The third quotes will be verified to report the data ASP Script URL. This is also be careful; when you are logon.asp 唔 喺 Eval Eval, Virtual Directory; 咁 will change you to set your generos. Its three: httpsendrequest is the fourth quotes, you will be the POST of the POST; 即 喺 UserId with Password. This must be the same as the name of the ASP Script. Once you have a mistake. . . I can't receive it. Zhong Yes, a Post data must be with the following format. Useridadmin & password = p @ SSW0RD UserId The name of the PASSWORD 喺, and the adminitcreated name value is the number of names. With the second declaration name, add a & 諕嚟 諕嚟 separate each declared name to the previous declaration name. When the ASP Script program is operated, the number of values ​​will be turned back; and a Win32 VC program will analyze the number of revolutions and the success of the login verification or failure. Experimental source code download: /files/hackzai/source/vc//httppost_code.zip

Long

PosttoremoteServer (LPBYTE PMESSAGE, LPHTTPINFO LPHI, LPBYTE POUTPUT,

int

nmaxbuffer {httpinfo httpinfo

=

{Null}; lpbyte lpdata

=

NULL; DWORD DWSIZE

=

0

DWORD DWRET

=

0

DWORD DWBYTEREAD

=

0

DWORD DWCONTENTLEN

=

0

DWORD DWBYTEAVAILABLE

=

0

Hinternet Hsession

=

NULL; Hinternet HCONNECTION

=

Null; Hinternet HopenRequest

=

NULL;

charr

Szheader []

=

"

Content-type: Application / X-WWW-FORM-URLENCODED / R / N

"

;

Long

LRESULT

=

0

__TRY {

//

Ensure the pass in arguement is valid

IF

(NULL)

==

LPHI) {

Return

-

9

}

IF

(NULL)

== poutput) {

Return

-

8

}

IF

(

0

==

nmaxbuffer {

Return

-

Seduce

}

//

Open a new instance of the internet access

HSession

=

Internetopen

"

Hackzai

"

, Internet_open_type_preconfig, null, null,

0

);

//

Checking The Internet Session Handle

IF

(NULL)

! =

Hsession) {

//

Connect to the Specified Server (IP)

HConnection

=

InternetConnect (HSession,

"

127.0.0.1

"

, Internet_Default_http_port, null,

"

HTTP / 1.1

"

, Internet_Service_HTTP,

0

,

0

);

//

Check The Internet Connect Handle Value

IF

(NULL)

! =

hconnection) {

//

Open a Request to the Current Server

HopenRequest

=

HttPopenRequest (HConnection,

"

POST

"

,

"

/EVAL/LOGON.ASP

"

,

"

HTTP / 1.1

"

NULL,

0

, Internet_flag_reload,

0

);

//

Check The OpenRequest Handle Value

IF

(NULL)

! =

HopenRequest) {

//

Add The Following Header Type

//

Content-Type: Application / X-WWW-FORM-URLENCODED

IF

(True

==

HttpaddRequestHeaders (HopenRequest, Szheader, Strlen (Szheader), http_addreq_flag_replace

|

HTTP_ADDREQ_FLAG_ADD)) {

//

Post The Message to Server Via "Post" Method

IF

(True

== httpsendrequest (HopenRequest, NULL,

0

, (Lpstr) PMessage, Strlen ((lpstr) pimentage))))

//

Get all the http information

DWSIZE

=

SizeOf (httpinfo.contenttype); httpqueryinfo (HopenRequest, http_query_content_type,

&

Httpinfo.conteType,

&

DWSIZE,

0

DWSIZE

=

SizeOf (httpinfo.contentLength; httpqueryinfo (HopenRequest, http_query_content_length,

&

Httpinfo.contentLength,

&

DWSIZE,

0

DWSIZE

=

SizeOf (httpinfo.querydate); httpqueryinfo (HopenRequest, http_query_date,

&

Httpinfo.Querydate,

&

DWSIZE,

0

DWSIZE

=

SIZEOF (httpinfo.server); httpqueryinfo (HopenRequest, http_query_server,

&

Httpinfo.server,

&

DWSIZE,

0

DWSIZE

=

SIZEOF (httpinfo.statuscode; httpqueryinfo (hopenrequest, http_query_status_code,

&

Httpinfo.statuscode,

&

DWSIZE,

0

DWSIZE

=

SizeOf (httpinfo.statustext); httpqueryinfo (hopenRequest, http_query_status_text,

&

Httpinfo.statustext,

&

DWSIZE,

0

);

//

Copy The Current Data Into The Output Buffer

CopyMemory (LPHI,

&

HTTPINFO, SIZEOF (httpinfo);

//

Reset Local Variable

DWContentlen

=

0

;

//

RESET Pass in Output Buffer

MEMSET (Poutput, NULL, NMAXBuffer);

//

Continue Query The Available Data Till the EOF //

Where the InternetQueryDataavailable Return False

While

(InternetQueryDataavailable (HopenRequest,

&

DWBYTEAVAILABLE,

0

,

0

)) {

//

Check The Current Data Available Download Size

IF

(dwbyteavailable

>

0

) {

//

Accumulate the data longth

DWContentlen

=

DWBYTEAVAOLABLE;

//

Allocate Memory

LPDATA

=

(Lpbyte) Localaloc (LPTR, DWBYTEAVAILABLE

1

);

//

Read file

DWRET

=

InternetReadfile (HopenRequest, LPDATA, DWBYTEAVAILABLE,

&

DWBYTEREAD);

//

Check Current Downloaded Data Agaist Pass in Buffer Size

IF

((

Long

Strlen (LPSTR) POUTPUT

(

Long

) DWBYTEAVAILABLE)

<

nmaxbuffer {

//

Append The Current Data Into The Pass in Output Buffer

STRNCAT (LPSTR) Poutput, (LPSTR) LPDATA, DWBYTEAVAILABLE;

//

Release The Allocate Memory

IF

(NULL)

! =

LPDATA) {localfree (lpbyte) lpdata;} lpdata

=

NULL;

Else

{

//

Set return value

LRESULT

=

(

Long

DWContentlen;

//

EXIT THE CURRENT WHILEND LOOP

Break

}}}

Else

//

Set return value

LRESULT

=

-

6

}

Else

//

Set return value

LRESULT

=

-

5

}

Else

//

Set return value

LRESULT

=

-

4

}

Else

//

Set return value

LRESULT

=

-

3

}

Else

//

Set return value

LRESULT

=

-

2

;

//

Jump Top CleaneXit Section

Goto cleanexit;} __except (exception_execute_handler) {//

PUT Your Error Handle Code Here

//

Set the return value

LRESULT

=

-

1

} Cleanexit:

//

Close All The Used Handle

IF

(NULL)

! =

HopenRequest) {internetCloseHandle (HopenRequest);

IF

(NULL)

! =

HConnection) {InternetCloseHandle (hconnection);

IF

(NULL)

! =

Hsession) {InternetCloseHandle (HSession);

//

Set Default Return Value

Return

LRESULT;

转载请注明原文地址:https://www.9cbs.com/read-56016.html

New Post(0)