简体   繁体   中英

How to do a POST request to an external API (vBulletin)?

How do you normally do a POST to an API in PHP?

For example:

login_login
Login a user and return a new session hash

Parameters
POST (Required)
vb_login_username - Username to login
Note that one of 3 vb_login_*password* methods is required.
vb_login_password - The password of the User. If client use this to login, the plain password may be sniffed during the pass in the network
vb_login_md5password - The md5 password of the User
vb_login_md5password_utf - The md5 password (Unicode) of the User

POST (Optional)
logintype - Possible value: 'cplogin' or empty. 'cplogin' means that the login will also allow the user to access the AdminCP if they have permission.

See here: https://www.vbulletin.com/forum/content.php/365-User-Related-Methods

More here: https://www.vbulletin.com/forum/content.php/334-mobile-api

So how would I do a POST to the API if the API script is located at http://somedomain.com/api.php ?

If I set the FORM ACTION to the external API page, it will send the user to that external site, so that obviously can't be the correct way.

Would I have to do a cURL POST? But that seems complicated for a simple API call.

Or do API's normally understand POST requests in a different and more straightforward manner?

Found the answer I was looking for:

http://code.google.com/apis/chart/image/docs/post_requests.html

See under "Using PHP for a POST Request".

Very straightforward and it worked.

If I understand correctly, you are trying to send a POST request to log in user remotely on some vBulletin and you want to use their API to do that.

So the question would be, what do you expect from that?

Do you expect to receive some confirmation data and use it to sign in user in your system or are you planning just a simple remote call?

ie you could simply do an Ajax request.

If it is more complicated and you need the API instance in your controller, I think it is better to make class on your side, that will use curl to send requests to their API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM