我正在對休息服務執行HttpPost以撤消許可證。在Android上,請求完美運行。HttpPost在C#中無法正常工作,但在Android中正常工作
@Override
protected String doInBackground(String... params)
{
String request = serverUrl + "api/Public/RemoveInstall?DeviceID="+deviceId+"&UserID="+m_userID;
try {
if(!isNetworkAvailable())
{
return "no_accesToken";
}
else
{
URL url = new URL(request);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setDoOutput(false);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("charset", "utf-8");
conn.setConnectTimeout(1500);
conn.setUseCaches(false);
conn.connect();
...
}
上面的代碼:但這樣做在C#中的帖子的時候,我得到的迴應
在Android中「沒有行動的請求匹配的控制器上找到」完美的作品,但在C#它不會工作:
public async Task<bool> RevokeLicenseAsync(string userId)
{
if (!IsInternetConnected())
{
errorMsg = "No internet connection";
return false;
}
string deviceId = GetDeviceID();
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("DeviceID", deviceId));
postData.Add(new KeyValuePair<string, string>("UserID", userId));
//the header arguments "ContentType" and "ContentLength are filled in automatically"
var formContent = new FormUrlEncodedContent(postData);
if (!String.IsNullOrEmpty(token))
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(serverUrl);
using (var response = await httpClient.PostAsync("api/Public/RemoveInstall",formContent))
{
第二個具有'=的'的DeviceID在POST,而不是GET –
在您發佈的URL的參數機器人請求,但第二個,你將它張貼在體內。如果第一個工作,然後對第二個工作也一樣。 – Nkosi
噢好吧我會考慮它感謝 – PrisonMike