mIRC Homepage
Posted By: Perl xml retaining structure or alternative - 18/08/15 11:04 PM
hello, you know you can create a simple client to connect to XML-RPC wordpress to publish post for example. but I try to send data from a file with $read, does not preserve the structure of xml me and gives me error, goes like this:

Code:
<?xml version="1.0"?>
<methodCall>
<methodName>metaWeblog.newPost</methodName>
<params>
<param>
<value>
<i4>1</i4>
</value>
</param>...



  and should go like this:

Code:
<?xml version="1.0"?>
<methodCall>
  <methodName>metaWeblog.newPost</methodName>
  <params>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>...



you know if there's any way to fix this? Greetings

pd: server response...
Code:
<value><string>parse error. not well formed</string></value>
Posted By: Loki12583 Re: xml retaining structure or alternative - 19/08/15 12:15 AM
Use $bread instead, but whitespace shouldn't be causing that error.
Posted By: Wims Re: xml retaining structure or alternative - 19/08/15 10:00 AM
That might just be an example but your xml isn't well formatted indeed, is the real file well formatted? unless you pastebin both the file and the code we can't help you much.

@loki: /bread confused
Posted By: Perl Re: xml retaining structure or alternative - 19/08/15 10:45 PM
hi, thanks for the help, try $bread and I had the same error, the client sends data socket this is the code:

Code:
alias connect {
    set %xmlinc 1
    set %xmlarchivo C:\Users\admin\Desktop\testxml.txt 
    sockopen xml $+ $rand(0,99999) domain.com 80
}

on 1:sockopen:xml*: {
    sockwrite -n $sockname POST /es/xmlrpc.php HTTP/1.1
    sockwrite -n $sockname Content-Type: text/xml
    sockwrite -n $sockname User-Agent: XML-RPC.NET
    sockwrite -n $sockname Host: domain.com
    sockwrite -n $sockname Content-Length: $len(%xmlarchivo)
    sockwrite -n $sockname Connection: Keep-Alive
    sockwrite -n $sockname $crlf
    
    while (%xmlinc <= $lines(%xmlarchivo)) {
      sockwrite -n $sockname $read(%xmlarchivo,%xmlinc)
      inc %xmlinc
    } 
}

on 1:sockread:xml*: {
  sockread %xmldatos
  echo -s %xmldatos 
}


and the server's response is the same:

Code:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=UTF-8
Content-Length: 403
Date: Wed, 19 Aug 2015 22:39:03 GMT
Accept-Ranges: bytes
Server: LiteSpeed
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>-32700</int></value>
</member>
<member>
<name>faultString</name>
<value><string>parse error. not well formed</string></value>
</member>
</struct>
</value>
</fault>
</methodResponse>



and the contents of the file is a publication xmlarchivo.txt in wordpress for XML-RPC protocol metaWeblog:


Code:
<?xml version="1.0"?>
<methodCall>
  <methodName>metaWeblog.newPost</methodName>
  <params>
    <param>
      <value>
        <i4>1</i4>
      </value>
    </param>
    <param>
      <value>
        <string>user</string>
      </value>
    </param>
    <param>
      <value>
        <string>pass</string>
      </value>
    </param>
    <param>
      <value>
        <struct>
          <member>
            <name>title</name>
            <value>
              <string>nuevo tituloooooooooo</string>
            </value>
          </member>
          <member>
            <name>description</name>
            <value>
              <string>&lt;iframe src="https://www.youtube.com/watch?v=v_Ci0z2rLLs" frameborder=0 width=510 height=400 scrolling=no&gt;&lt;/iframe&gt;</string>
            </value>
          </member>
          <member>
            <name>categories</name>
            <value>
              <array>
                <data>
                  <value>
                    <string>accion</string>
                  </value>
                </data>
              </array>
            </value>
          </member>
          <member>
            <name>post<name>mt_keywords</name>
            <value>
              <string>tag1,tag2</string>
            </value>
          </member>
          <member>
            <name>custom_fields</name>
            <value>
              <array>
                <data>
                  <value>
                    <struct>
                      <member>
                        <name>key</name>
                        <value>
                          <string>duration</string>
                        </value>
                      </member>
                      <member>
                        <name>value</name>
                        <value>
                          <string>1:02</string>
                        </value>
                      </member>
                    </struct>
                  </value>
                  <value>
                    <struct>
                      <member>
                        <name>key</name>
                        <value>
                          <string>image</string>
                        </value>
                      </member>
                      <member>
                        <name>value</name>
                        <value>
                          <string>http://www.images.com.jpg</string>
                        </value>
                      </member>
                    </struct>
                  </value>
                  <value>
                    <struct>
                      <member>
                        <name>key</name>
                        <value>
                          <string>ID</string>
                        </value>
                      </member>
                      <member>
                        <name>value</name>
                        <value>
                          <string />
                        </value>
                      </member>
                    </struct>
                  </value>
                  <value>
                    <struct>
                      <member>
                        <name>key</name>
                        <value>
                          <string>video</string>
                        </value>
                      </member>
                      <member>
                        <name>value</name>
                        <value>
                          <string>http://www.youtube.com/watch?v=T_2jF-_LnNg</string>
                        </value>
                      </member>
                    </struct>
                  </value>
                </data>
              </array>
            </value>
          </member>
        </struct>
      </value>
    </param>
    <param>
      <value>
        <boolean>1</boolean>
      </value>
    </param>
  </params>
</methodCall>


publish feel much, but that I think is complete and no missing data, if you can give me some help, I is not doing wrong, and no more try ... Greetings
Posted By: Loki12583 Re: xml retaining structure or alternative - 19/08/15 11:29 PM
$len(%xmlarchivo) returns the length of the filename string, not the size of the file, use $file(%xmlarchivo).size

You'll need to /bread with this method because $read() will strip the whitespace and mess up the content-length
Posted By: Perl Re: xml retaining structure or alternative - 21/08/15 10:38 AM
Thanks Loki12583, because tests have to do with bread, to see if I can work well, thank you both for the great help. Regards.
Posted By: Perl Re: xml retaining structure or alternative - 23/08/15 11:14 PM
Hi, I managed to pass binary variable data file. and I've replaced $len, use $file(%xmlarchivo).size . but I can not read the second line of the file my code is this:


Code:
alias testb {
  bread -t $qt(%xmlarchivo) 0 99999999 &tempFile
  echo -s $bvar(&tempFile,1,10000).text
}


result:

Code:
<?xml version="1.0"?>

is always line 1 of file.

and the result gives the first line of the file, but if I remove parameter "-t" in bread, me too long is a line that fails to send sockwrite to be too long. there any solution? and I not know what else to try, thanks and greetings.
Posted By: Loki12583 Re: xml retaining structure or alternative - 23/08/15 11:23 PM
You send it directly with /sockwrite $sockname &tempFile
Posted By: Perl Re: xml retaining structure or alternative - 24/08/15 12:20 AM
Originally Posted By: Loki12583
You send it directly with /sockwrite $sockname &tempFile


Loki12583 many thank you very much, now works well, can feel to much, but I'm new to many things and did not know how to do it, that was the solution.

Thanks wims and Loki12583, a greeting.
© mIRC Discussion Forums