【发布时间】:2014-11-10 14:35:31
【问题描述】:
我编写了以下代码来调用 Web 服务数据输出并且它有效。问题是当我在 Web 软件上激活 api 密钥并生成此密钥时,调用 Web 服务并需要创建一个 api 客户端通过 httpRequest 请求这个,但是每当我运行它时我的问题是“远程服务器返回错误:(404)未找到。”你有什么主意吗?我将整个代码粘贴在下面。
非常感谢您
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DisplayDataInformation
{
public partial class DisplayDataInformation : Form
{
public DisplayDataInformation()
{
InitializeComponent();
}
private void Submit(object sender, EventArgs e)
{
localhost.Dashboard proxy = new localhost.Dashboard();
localhost.ProjectMetaData[] pm = proxy.GetAllProjectMetaData();
const string URL = "http://localhost/myProgram/";
const string apiKey = "d26b15b5-e336-48de-9142-939c0e639e8f";
const string Id = "Id";
const string Pass = "pass";
System.Net.HttpWebRequest myHttpWReq;
System.Net.HttpWebResponse myHttpWResp;
//myHttpWReq.ContentLength = 0;
// Make a web request to the web service
myHttpWReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(BLUEURL + "http://localhost/myProgram/Dashboard.asmx" + Id + Pass + apiKey);
myHttpWReq.Method = "Get";
// Get the response of the web service
myHttpWResp = (System.Net.HttpWebResponse)myHttpWReq.GetResponse();
if (myHttpWResp.StatusCode == System.Net.HttpStatusCode.OK)
{
//Create an XML reader to parse the response
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(myHttpWResp.GetResponseStream());
}
//set an string output to the windows form
StringBuilder sb = new StringBuilder();
foreach (localhost.ProjectMetaData value in pm)
{
sb.AppendLine(value.ProjectTitle + " - "
+ value.ProjectID + " - "
+ value.PublishStatus );
// sb.AppendLine("\r\n\t");
}
label1.Text = sb.ToString();
}
}
}
【问题讨论】:
标签: c# web-services http client api-key