wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
338 stars 129 forks source link

Media.Create Server returned HTTP status Forbidden #156

Closed toby11 closed 5 years ago

toby11 commented 5 years ago

All other create/update delete functions seem to work fine. However when trying to create media using

var createdMedia = await client.Media.Create(@"d:\\test4.png", "test4.jpg");

I get this error "Server returned HTTP status Forbidden"

I know this is probably a wordpress config issue but any ideas why?

<h1>Forbidden</h1>
<p>You don't have permission to access /wordpresstesting/wp-json/wp/v2/media
on this server.<br />
</p>
<p>Additionally, a 403 Forbidden
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
ThomasPe commented 5 years ago

Probably not the issue at hand, but you're trying to save a png named ".jpg" - is that by design?

toby11 commented 5 years ago

Sorry - both should be .jpg - it was from where I was testing with different file types. Tested again and still same issue. thanks

polushinmk commented 5 years ago

May be user from whom you are logged in haven`t enough rights for media files uploading?

toby11 commented 5 years ago

No I don't think so as it's the original admin user and I can upload images fine from WordPress logged in as that user. I can give you the connection details if you want to try connecting as it's only a test site. Thanks

polushinmk commented 5 years ago

@toby11 ok, you can send info to mail (in my profile)

toby11 commented 5 years ago

@polushinmk ok thanks - just sent it over.

NB FYI this is Wordpress installed automatically from cPanel – using softaculous.

polushinmk commented 5 years ago

@toby11 Interesting thing. The problem is in Content-Type header. I tried to send a request without this header and all works fine. Seems, that web-server blocks requests with content-type like 'image/*' (jpeg, png etc). Check htaccess settings and settings in cPanel.

toby11 commented 5 years ago

@polushinmk ok great, thanks for having a look - I will have a look at the config.

toby11 commented 5 years ago

@polushinmk thanks yes that was it. its all working now.

It was a rule setup in mod_security by my hosting provider

ID: 920420 [msg "Request content type is not allowed by policy"] [data "image/jpeg"]