Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to inspect the request as it's sent to the server? #8

Closed
SHxKM opened this issue Dec 24, 2015 · 2 comments
Closed

Any way to inspect the request as it's sent to the server? #8

SHxKM opened this issue Dec 24, 2015 · 2 comments

Comments

@SHxKM
Copy link

SHxKM commented Dec 24, 2015

There's an issue I've been dealing with for the last 3-4 days, and no matter how I try to construct my method in Swift syntax, I'm getting errors.

The method is part of the WP XMLRPC API and is called wp.newPost. The documentation states that we need to pass the following in the method parameters: (WordPress uses PHP)

  • int blog_id
  • string username
  • string password
  • struct content
    • string post_type
    • string post_status
    • string post_title
    • int post_author
    • string post_excerpt
    • string post_content
    • more...

I'm 100% certain that the problem lies in the way I'm passing the struct content part, as all other paramters I've passed worked with other methods.

When I check my server logs, this is the PHP error I'm seeing:

Cannot unset string offsets in /nas/content/live/sitename/wp-includes/class-wp-xmlrpc-server.php on line 1212

These are the lines referenced:

1209:                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
1210:                do_action( 'xmlrpc_call', 'wp.newPost' );
1211:
1212:                unset( $content_struct['ID'] );
1213:
1214:                return $this->_insert_post( $user, $content_struct );

My question is: How can I see the XMLRPC request that I'm sending, and possible see how things are getting passed?

Code snipper from the method:

 let myInfo:[String: String] = ["post_title": "Hi there", "post_content": "Hello"]



    let headeros = ["User-Agent": "xApp"]



    let params: [Any] = [0, "\(WP_USERNAME)", "\(WP_PASSWORD)", myInfo]



    AlamofireXMLRPC.request("\(WP_URL)", methodName: "wp.newPost", parameters: params, headers: headeros).responseString {



        (response:Response<String, NSError>) -> Void in

        guard response.result.isSuccess else {

            print("Error in clause response isSucess for wp.newPost method")

            print(response.result.error)

            return

        }





        let davalue = response.result

        print(davalue)

response.result.value prints:

Optional("")

response.result prints:

SUCCESS

po response prints:

[Request]: <NSMutableURLRequest: 0x7ffa40516cc0> { URL: http://websiteurl.com/xmlrpc.php }

[Response]: <NSHTTPURLResponse: 0x7ffa40704a80> { URL: http://websiteurl.com/xmlrpc.php } { status code: 500, headers {

    Connection = "keep-alive";

    "Content-Length" = 0;

    "Content-Type" = "text/html";

    Date = "Thu, 24 Dec 2015 14:35:10 GMT";

    "Keep-Alive" = "timeout=20";

    Server = nginx;

} }

[Data]: 0 bytes

[Result]: SUCCESS: 

  ▿ request : Optional(<NSMutableURLRequest: 0x7ffa40516cc0> { URL: http://websiteurl.com/xmlrpc.php })

  ▿ response : Optional(<NSHTTPURLResponse: 0x7ffa40704a80> { URL: http://websiteurl.com/xmlrpc.php } { status code: 500, headers {

    Connection = "keep-alive";

    "Content-Length" = 0;

    "Content-Type" = "text/html";

    Date = "Thu, 24 Dec 2015 14:35:10 GMT";

    "Keep-Alive" = "timeout=20";

    Server = nginx;

} })

  ▿ data : Optional(<>)

  ▿ result : SUCCESS: 

    - Success : ""

You can also see that the headers I've specified were NOT passed.

@SHxKM
Copy link
Author

SHxKM commented Dec 24, 2015

Another method which achieves the same thing (new post), give the following response:

("\n\n \n \n \n \n faultCode\n 500\n \n \n faultString\n Content, title, and excerpt are empty.\n \n \n \n \n\n")

@SHxKM SHxKM closed this as completed Dec 24, 2015
@ilg
Copy link
Contributor

ilg commented Dec 28, 2015

Without paying much attention to the body of your question, the title brought to mind Charles Proxy—that's what I use to inspect (and modify!) network requests and responses on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants