我正在尝试从 android 触发我的 ASP.NET Web 应用程序中的创建操作。
该代码似乎工作正常,没有错误。我在 Windows 7 中使用 IIS 6。我怀疑 IIS 中缺少配置?
我没有在网络应用程序中获得价值。
安卓代码:
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("supplier_name",
"Thein Htike Aung"));
HttpClient client1 = new DefaultHttpClient();
HttpPost request =
new HttpPost("http://192.168.1.104/LogicUniversity/SupplierHandler.ashx");
try {
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
request.addHeader("Content-type", "application/x-www-form-urlencoded");
HttpResponse response = client1.execute(request);
BufferedReader in = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent()));
String line;
String page="";
line = in.readLine();
while(line!=null)
{
page=page+line;
line=in.readLine();
}
Log.i("Page",page);
in.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
在 Web 处理程序中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ApplicationLayer.Controllers;
using ApplicationLayer;
namespace PresentationLayer
{
/// <summary>
/// Summary description for SupplierHandler
/// </summary>
public class SupplierHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string name = context.Request.QueryString["supplier_name"];
if (name != null)
{
Supplier s = new Supplier();
s.supplier_name = name;
s.code = "TEST";
new SupplierController().actionCreateSupplier(s);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}