0
Web WebサービスをHTTP WebRequestで呼び出す。そのうまくいくが、パラメータに特殊文字を渡すとエラー404が発生する。ページが見つかりません..webrequestを使用してwcfサービスを使用すると、404エラーが発生するgetmethod
ここにMy Code Snippetがあります。
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Data/{username}/{password}")]
string RequestData(string userName, string password);
public string RequestData(string userName, string password)
{
// Here is My Logic Comes
}
// Here im Calling This Service in My ASPX Page
HttpWebRequest req = null;
HttpWebResponse res = null;
try
{
const string url = "http://localhost:53366/AuthService.svc/Data/[email protected]/password#1"; // Here Gives Error 404 Page Not Found
//const string url = "http://localhost:53366/AuthService.svc/Data/test/password"; // Here Works Fine When I Pass This Paramters Without Special Characters
req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "Get";
req.ContentType = "application/json; charset=utf-8";
req.Headers.Add("AppID", "MobileApplication");
res = (HttpWebResponse)req.GetResponse();
Stream responseStream = res.GetResponseStream();
var streamReader = new StreamReader(responseStream);
txtTokenRespoonse.Text = streamReader.ReadToEnd();
streamReader.Close();
streamReader.Dispose();
responseStream.Close();
responseStream.Dispose();
}