如何使用 ASP.NET C# 向 web api 发送和接收答案

我必须在 XML 中调用一个使用 EPP(可扩展配置协议)的 Web API,并返回一个 XML 作为响应。我还需要使用证书来调用它,但是收到的响应为空。PHP 中只有一个示例代码可以工作。


eppClient.php


<?php 

require_once 'config.php';

require_once 'eppFunctions.php';


//Get XML variable via POST method 

$xmlStr = stripslashes(trim($_POST['xmlStr']));


$response = send_epp_request($USER_CERTIFICATE_FILE, $EPP_SERVER_URL, $xmlStr);


if(!$response === false){


    //Show Server Response as XML

    header("Content-type: application/xml");

    echo $response;


}

?>

配置文件


<?php

//Server URL Address For Sending XML

$EPP_SERVER_URL = "api.site.com/submit";


//URL CERTIFICATE FILE

$USER_CERTIFICATE_FILE = "";

?>


动漫人物
浏览 199回答 2
2回答

慕的地10843

尝试这个。string data = "{}";WebRequest myReq = WebRequest.Create(url);&nbsp;//set webreuqest properties e.g&nbsp; &nbsp; //myReq.Method = "POST";&nbsp; &nbsp; //myReq.ContentLength =&nbsp; lenght;&nbsp;UTF8Encoding enc = new UTF8Encoding();&nbsp;using (Stream ds = myReq.GetRequestStream())&nbsp;{&nbsp;ds.Write(enc.GetBytes(data), 0, data.Length);&nbsp;}&nbsp;using (WebResponse wr = myReq.GetResponse())&nbsp;{&nbsp;Stream receiveStream = wr.GetResponseStream();&nbsp;using (StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8)){&nbsp; &nbsp; string content = reader.ReadToEnd();}}
打开App,查看更多内容
随时随地看视频慕课网APP