How could I make a PHP webservice to receive data from third parties?
I'm creating a webservice in which remote sites can send data to a PHP-based webservice. However, I'm struggling to come up with the best way of handling the incoming data.
The data will be in the form of sh开发者_开发问答opping basket contents, so might include product name, price, ID, date, customer etc. There will be one line of data for each product in the basket, so there could be 20-30 lines for some customers.
Would sending the data to the webservice via GET be sensible? Is there a better option you can think of? Any input is greatly appreciated.
Thanks!
Probably not a great idea to send via get. I'd generate the basket as XML or JSON, then post it to the service. You can then write back a response on XML or JSON saying whether or not the call was successful.
A nice introduction to a RESTful API with PHP is here. I find it goes a bit overboard in some places, you can do the same with a little less code but it is nonetheless a good guide.
If the request is going to be making a change, I would not use GET. It would break GET's safety. Here's the HTTP spec on safe methods: RFC 2616.
I would recommend you look towards a REST architecture where it seems like a POST or possibly a PUT request should be used.
精彩评论