3

i want to change xml value in php but don't change ....

<?php

$url = "http://192.168.1.103:8080/ew.xml";
$xml = '<?xml version="1.0" ?>
<DDCConfig:getValue xmlns:DDCConfig="urn:SMUDDCConfiguration">
<DDCConfig:Network>
 <DDCConfig:LocalIP>192.168.103.223</DDCConfig:LocalIP>
 <DDCConfig:GlobalIP>168.188.127.123</DDCConfig:GlobalIP>
<DDCConfig:RootBridge>Yes</DDCConfig:RootBridge>
</DDCConfig:Network>
</DDCConfig:getValue>';

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_USERPWD, "lmk:alrud89");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_URL, "$url"); 
curl_setopt($ch, CURLOPT_PORT, 8080);
curl_setopt($ch, CURLOPT_PUT, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,array($xml));
$http_result = curl_exec($ch);
if($http_result){
echo $http_result;
}else{
echo curl_error($ch);
}

curl_close($ch); 
?>

error message is

* About to connect() to 192.168.1.103 port 8080 (#0) * Trying 192.168.1.103...
* connected
* Server auth using Basic with user 'lmk'
> PUT /ew.xml HTTP/1.1
> Authorization: Basic bG1rOmFscnVkODk=
> Host: 192.168.1.103:8080 Accept: /
> Transfer-Encoding: chunked
> Expect: 100-continue
< HTTP/1.1 401 Unauthorized
< Content-Length: 0
<
> WWW-Authenticate: Digest qop="auth", realm="mydomain.com", nonce="1366254379"
* HTTP error before end of send, stop sending
* Closing connection #0

what is the problem & solution?

4
  • is there any thing listening on that ip? Commented Apr 18, 2013 at 3:17
  • One thing I can see right of the bat (not directly related to your auth error) is that you're not passing an associative array for the POST_FIELDS. Your POST data is XML, but it also needs to have a name. Commented Apr 18, 2013 at 3:19
  • @Dagon yes otherwise he would get error 404 Commented Apr 18, 2013 at 3:26
  • @Dagon no...but i can see the data by firefox Commented Apr 18, 2013 at 3:30

1 Answer 1

2

Your credentials are incorrect! (that's what error 401 means)

There's a wonderful plugin for Firefox called poster - install it and use it to double-check that the request is formatted correctly.

By the way, you might want to add the following header:

curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml"))

Another thing: PUT is not always supported, try POST - sometimes it'll work.

Sign up to request clarification or add additional context in comments.

6 Comments

@user2235070 did you get the same response using poster ?
oh you were right . I change 'POST' instead of 'PUT'..it works!
Like AgilE said, try replacing array($xml) with $xml
you mean this part? curl_setopt($ch, CURLOPT_POSTFIELDS,array($xml)); i already did..not work...not change data...
@user2235070 in that case you need to debug it from the server-side, start with checking the server logs, see if there's any error. Did you add the content-type header like I showed ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.