C#post方法在localhost上有效,但在共享主机上不可用

时间:2019-03-07 14:19:50

标签: c# laravel cpanel shared-hosting

我正在测试一个使用方法post从“ myhost / post_test ”中获取数据的C#应用​​程序:

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失败

1 个答案:

答案 0 :(得分:0)

我已经弄清楚了,我将它们添加到了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";