SQS SendMessage & $_POST Issue - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, September 14, 2022

SQS SendMessage & $_POST Issue

If I put $author='Steven King'; it works without issue, however it does not work with a post variable.

To be "clear" if I hard code the the author in the JSON it will in fact post the message to the SQS queue. This is the expected result, however if I pass the string from the Post Variable e.g. $author=$_POST['author], the message is never delivered.

$message = array(
                    // Associative array of custom 'String' key names
                    'Author' => array(
                        'StringValue' =>$author,
                        'DataType' => 'String'
            ),
        );

Any thoughts or help on this I would be grateful.

<?php
    $author =$_POST["author"];
    
    require 'vendor/autoload.php';
    use Aws\Common\Aws;
    use Aws\Sqs\SqsClient;
    use Aws\Exception\AwsException;
    
    
    // Get the client from the builder by namespace
    
    $client = SqsClient::factory(array(
        'profile' => 'default',
        'region'  => 'us-west-2',
        'version' => '2012-11-05'
    ));
    
    $queueUrl ='https://sqs.us-west-2.amazonaws.com/blahblahblah';
    
    
    $message = array(
                    // Associative array of custom 'String' key names
                    'Author' => array(
                        'StringValue' =>$author,
                        'DataType' => 'String'
            ),
        );
    
    var_dump($message);
    $result = $client->sendMessage(array(
    'QueueUrl' => $queueUrl,
    'MessageBody' => 'An awesome message!',
    'MessageAttributes' =>$message,
    ));


source https://stackoverflow.com/questions/73706549/sqs-sendmessage-post-issue

No comments:

Post a Comment