Bonjour à tous,

J'aurais besoin d'un coup de main pour transformer un code php en c#

Php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
<?php
// First we need to feed the techdata SKU, for now we use 1088963 as an example
$td_sku="1088963";
//Following the XML data
$xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r
<OnlineCheck>\r
<Header>\r
<BuyerAccountId>------</BuyerAccountId>\r
<AuthCode>---------</AuthCode>\r
<Type>Full</Type>\r
</Header>\r
<Item line=\"1\">\r
<ManufacturerItemIdentifier/>\r
<ResellerItemIdentifier/>\r
<DistributorItemIdentifier>$td_sku</DistributorItemIdentifier>\r
<Quantity>1</Quantity>\r
</Item>\r
</OnlineCheck>";
$fp = fsockopen("intcom.xml.techdata-europe.com", 8080, $errno, $errstr, 15);
//Generate the postdata on a valid way, $out4 needs to be calculated, so will be later.
$out1 = "POST /Onlchk HTTP/1.0\r
";
$out2 = "Content-Type: multipart/form-data; boundary=---------------------------2\r
";
$out3 = "Host: intcom.xml.techdata-europe.com:8080\r
";
$out5 = "Connection: close\r
\r
";
$out6 = "-----------------------------2\r
";
$out7 = "Content-Disposition: form-data; name=\"onlinecheck\"\r
\r
";
$out8 = "\r
-----------------------------2--";
//Calculation of the Content-Length:
$tlen=strlen($out6)+strlen($out7)+strlen($xmldata)+strlen($out8);
$out4 = "Content-Length: $tlen\r
";
//Generate full output
$out = $out1.$out2.$out3.$out4.$out5.$out6.$out7.$xmldata.$out8;
fwrite($fp, $out);
$retval = "";
while(!feof($fp)){$retval = "$retval".fgets($fp,128);}
fclose($fp);
list($headers,$body) = explode("<?xml version=\"1.0\" encoding=\"UTF-8\"?>",$retval);
$doc = new DOMDocument();
$doc ->LoadXML($body);
$item_ids = $doc->getElementsByTagname( "OnlineCheck" );
foreach( $item_ids as $item )
{
$error_s = $item->getElementsByTagName( "Errorstatus" ); $tderror = $error_s->item(0)->nodeValue;
$stock_s = $item->getElementsByTagName( "AvailabilityTotal" ); $tdstock = $stock_s->item(0)->nodeValue;
// Reformatting the price to ISO compatible format
$price_s = $item->getElementsByTagName( "UnitPriceAmount" ); $tdprice = str_replace('.','',$price_s->item(0)->nodeValue);
$tdprice=str_replace(',','.',$tdprice);
}
//Rest of handling off the data under here
?>
J'ai essayé ceci mais sans succès..
C#
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
            String xmldata="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
            xmldata += "<OnlineCheck>";
            xmldata += "<Header>";
            xmldata += "<BuyerAccountId>" + this.lcAccount + "</BuyerAccountId>";
            xmldata += "<AuthCode>" + this.lcAuthCode + "</AuthCode>";
            xmldata += "<Type>Full</Type>";
            xmldata += "</Header>";
            xmldata += "<Item line=\"1\">";
            xmldata += "<ManufacturerItemIdentifier/>";
            xmldata += "<ResellerItemIdentifier/>";
            xmldata += "<DistributorItemIdentifier>BROTHER2070N</DistributorItemIdentifier>";
            xmldata += "<Quantity>1</Quantity>";
            xmldata += "</Item>";
            xmldata += "</OnlineCheck>";
 
            HttpWebRequest req = (HttpWebRequest)
            WebRequest.Create("http://intcom.xml.techdata-europe.com:8080");
            req.Method = "POST";
            req.ContentType = "text/xml";
            req.ContentLength = xmldata.Length;
 
            StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            stOut.Write(xmldata);
            stOut.Close();
 
            WebResponse webResponse2 = req.GetResponse();
 
            Stream stream2 = webResponse2.GetResponseStream();
            StreamReader reader2 = new StreamReader(stream2);
 
            MessageBox.Show(reader2.ReadToEnd());
j'ai un "acces forbiden" a la lecture
une idée?