我正在测试一个C#应用程序,它使用方法post从“myhost / post_test”获取数据:
var client = new WebClient();
var data = new NameValueCollection();
data["email"] = email_input.Text;
data["password"] = pw_input.Text;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol
= SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
var response = client.UploadValues("myhost/post_test", "POST", data);
对于myhost是http://localhost:8000/它的工作原理,但是
对于myhost是https://example.com/它没有(返回405错误代码 - 方法不允许)。
我在我的网站上使用Laravel 5.7框架,.htaccess文件如下:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Authorization Header
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-alt-php72___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
是什么导致了这个问题?提前致谢。
编辑1:我将放置我在这里使用的路线:
Route::group(['prefix'=>'client_server_protocol'],function(){
Route::group(['prefix'=>'version19'],function(){
Route::post('login','AppController@postLogin');
Route::post('AuthCheck','AppController@postAuthCheck');
Route::post('ask_hrs_to_auth_check','AppController@postAsk_hrs_to_auth_check');
});
});
它在“登录”Route :: post失败了
我已经弄明白了,我将这些添加到webclient对象并解决了一些问题:
client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)";
client.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
client.Headers["Accept-Language"] = "en-us,en;q=0.5";
client.Headers["Accept-Encoding"] = "gzip,deflate";
client.Headers["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";