Ich habe folgende PHP Class, die ich gern in C# hätte
Ich habe folgendes verwendet:
https://sourceforge.net/projects/libcurl-net/
https://blog.iarivas.com.ar/using-curl-with-c-net/
Mein Code:
Leider erhalte ich keine Rückgabe auch lande ich gar nicht in der OnWriteData beim Debuggen.
Jemand eine Idee??
Code:
class Adns {
function call ($data) {
$xml = new XML_Converter();
$data=to_utf8($data);
$req = $xml->hash_to_xml( $data );
$res = $this->requestCurl( $req );
return $xml->xml_to_hash( $res );
}
function requestCurl( $request ) {
$ch = curl_init( HOST );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $request );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if( !$response=curl_exec( $ch )) {
echo " Curl execution error". curl_error( $ch ) ."\n".curl_errno($ch)."\n";
return FALSE;
}
curl_close( $ch );
# remove keep alive header
while(substr($response, 0, 21) == "HTTP/1.1 100 Continue") {
$response = substr($response, 25);
}
return $response;
}
}
Ich habe folgendes verwendet:
https://sourceforge.net/projects/libcurl-net/
https://blog.iarivas.com.ar/using-curl-with-c-net/
Mein Code:
Code:
protected void Page_Load(object sender, EventArgs e)
{
sourceContent = new StringBuilder();
try
{
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Easy easy = new Easy();
Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
easy.SetOpt(CURLoption.CURLOPT_URL, @"DIEURL");
StringWriter strw = new StringWriter();
XmlTextWriter wr = new XmlTextWriter(strw);
wr.WriteStartDocument();
wr.WriteStartElement("request");
//-->Authblock
wr.WriteStartElement("auth");
wr.WriteElementString("user", "xxxx");
wr.WriteElementString("password", "xxxxxx");
wr.WriteElementString("context", "xxxx");
wr.WriteEndElement();
//<--Authblock
//Mehr XMLDaten
wr.WriteEndElement();
//<--task
wr.WriteEndElement();
wr.WriteEndDocument();
easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, strw.ToString());
easy.SetOpt(CURLoption.CURLOPT_POST, 1);
easy.SetOpt(CURLoption.CURLOPT_READDATA, true);
easy.SetOpt(CURLoption.CURLOPT_WRITEDATA, true);
easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, false);
easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
easy.Perform();
easy.Cleanup();
Curl.GlobalCleanup();
}
catch (Exception ex)
{
}
ausgabe.InnerHtml = sourceContent.ToString();
}
public Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
{
this.sourceContent.Append(System.Text.Encoding.UTF8.GetString(buf));
return size * nmemb;
}
Leider erhalte ich keine Rückgabe auch lande ich gar nicht in der OnWriteData beim Debuggen.
Jemand eine Idee??