将代码放在我的HttpPost请求中
async void ContinueBtn_Clicked(object sender, EventArgs e)
{
if (!CheckValidation())
{
LoginBLL cust = new LoginBLL();
EncryptPassword encrypt = new EncryptPassword();
cust.name = txtFieldName.Text;
cust.email = txtFieldEmail.Text;
cust.Password = encrypt.HashPassword(txtFieldPass.Text);
cust.profession = txtFieldJob.Text;
cust.company = txtFieldCompany.Text;
cust.subId = 1320;
HttpClient client = new HttpClient();
string url = "https://www.example.com/api/customer/";
var uri = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response;
var json = JsonConvert.SerializeObject(cust);
var content = new StringContent(json, Encoding.UTF8, "application/json");
response = await client.PostAsync(uri, content);
if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
{
validationName.Text = await response.Content.ReadAsStringAsync();
}
else
{
validationName.Text = await response.Content.ReadAsStringAsync();
}
}
执行上述功能时出现此错误
未找到与请求URI'https://www.example.com/api/customer/'相匹配的HTTP资源。
但是在具有相同变量的Postman中它可以正常工作。
我什至验证了POSTMAN中生成的JSON与Visual Studio中生成的JSON是完全相同的。
我正在iPhone 8 iOS 12.0上运行它