1

私は与えました

[WebGet(UriTemplate = "/{year}/{issue}/{article}")] 

Article GetArticle(string year, string issue, string article); 

[OperationContract] 

[WebInvoke(UriTemplate = "/{year}/{issue}",Method="POST")] 

Article AddArticle(string year, string issue, Article article);

私の URL はhttp://localhost:1355/Issues.svc/ です

これを指定すると、データベースからすべてのデータを取得しています

http://localhost:1355/Issues.svc/2010/June/A

GetArticle メソッドは、フィルタリングされたデータを db から取得するために起動します。

同様に、データベースにデータを挿入するには、Add Article(WebInvoke) メソッドを呼び出す必要があります。ブラウザでこのメソッドを呼び出すにはどうすればよいですか

method=postを指定する必要がある私のURLはどうあるべきか

4

3 に答える 3

1

この投稿をチェックして、必要なタスクを達成するのに役立ててください:WCFでRESTサービスを作成し、jQueryを使用して消費する

于 2011-04-08T04:43:54.597 に答える
1

URL を変更しただけでは、ブラウザーから HTTP 投稿を送信することはできません。HTML フォーム、Javascript コード、サーバー側コード、またはサービス URL に対して HTTP POST 要求を行う機能を備えた何かを含む Web ページが必要です。

開発中にサービスをテストしたいだけの場合は、http: //fiddler2.comをチェックしてみてください。

于 2011-04-08T04:48:25.867 に答える
0

ブラウザの URL を使用して投稿することはできません。

このコードを試してください

//Creating the Web Request.
HttpWebRequest httpWebRequest = HttpWebRequest.Create("http://localhost/DemoApp/Default.aspx") as HttpWebRequest;
//Specifing the Method
httpWebRequest.Method = "POST";
//Data to Post to the Page, itis key value pairs; separated by "&"
string data = "Username=username&password=password";
//Setting the content type, it is required, otherwise it will not work.
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
//Getting the request stream and writing the post data
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    sw.Write(data);
}
//Getting the Respose and reading the result.
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream()))
{
    MessageBox.Show(sr.ReadToEnd());
}

ソース: http://www.dotnetthoughts.net/2009/11/10/post-data-using-httpwebrequest-in-c-sharp/

于 2011-04-08T04:51:32.097 に答える