WebFaction
Community site: login faq

Hello,

Im trying to do this for uploading an image into a product in Prestashop: ...

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $key.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

... But always I got an HTTP 1.1 401 Error. Server:Nginx

In my old VPS was working good,just Apache, but now not. I think is something related with Nginx server, which is not allowing this kind of request.

Any idea?

Thanks

asked 31 Jul '14, 01:57

manu7691
11114
accept rate: 100%

edited 03 Aug '14, 23:40


Finally the problem wasnt Nginx, was related with CGI Apache.

I applied this solution and now it is working : http://planetozh.com/blog/2009/04/http-authentication-on-php-as-cgi-like-dreamhost/

permanent link

answered 03 Aug '14, 23:38

manu7691
11114
accept rate: 100%

401 means that the URL to which you're trying to post requires authentication credentials that you either are not providing, or are not providing in the correct manner.

First, verify that the credentials that you provding in $key are correct.

If they are, then try adding either of the following lines before your CURLOPT_USERPWD line:

curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

or

curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
permanent link

answered 31 Jul '14, 19:41

seanf
12.2k41836
accept rate: 37%

edited 31 Jul '14, 21:16

I'm providing the key in $key. As I tell before, in Apache server was working so i dont know what is the problem with Nginx server.

(31 Jul '14, 21:06) manu7691

Ok, I've updated my answer with more info.

(31 Jul '14, 21:16) seanf

I tried it and still the same error :S

(01 Aug '14, 11:01) manu7691

I'm starting to think you're simply passing the wrong credentials.

$key should contain a string like 'username:password'. You're adding a colon to the end of it, like 'username:password:'. Maybe try it without the ending colon?

If that doesn't work, then I suggest that you open a support ticket and give us the exact details and steps we would need to reproduce the problem, and we'll try to assist that way.

(01 Aug '14, 15:11) seanf
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×262
×225
×186
×31
×15

question asked: 31 Jul '14, 01:57

question was seen: 14,559 times

last updated: 03 Aug '14, 23:40

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM