2017-06-16 4 views
0

Pouvez-vous m'aider s'il vous plaît?Symfony Post recevoir des données avec la forme, mais pas avec Rest client

J'utilise l'extension avancée du client Chrome pour tester mon api symfony. mon problème est quand j'envoie des données de poste, la variable $ _POST et $ request est vide. Mais j'ai dans mon wampserver un formulaire pour le test.

<form action="url" method="post"> 
<input name="access_token" value="my token"/> 
<input name="json" value='here my json file' /> 
<input type="submit" class="btn btn-primary" value="send" name="send" /> 
</form> 

Je vérifie url est juste, et dans ces deux cas, je vais dans le contrôleur. Je ne pense pas problème est avec mon .htaccess:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Determine the RewriteBase automatically and set it as environment variable. 
    # If you are using Apache aliases to do mass virtual hosting or installed the 
    # project in a subdirectory, the base path will be prepended to allow proper 
    # resolution of the app.php file and to redirect to the correct URI. It will 
    # work in environments without path prefix as well, providing a safe, one-size 
    # fits all solution. But as you do not need it in this case, you can comment 
    # the following 2 lines to eliminate the overhead. 
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 

    # Sets the HTTP_AUTHORIZATION header removed by apache 
    RewriteCond %{HTTP:Authorization} . 
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

    # Redirect to URI without front controller to prevent duplicate content 
    # (with and without `/app.php`). Only do this redirect on the initial 
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an 
    # endless redirect loop (request -> rewrite to front controller -> 
    # redirect -> request -> ...). 
    # So in case you get a "too many redirects" error or you always get redirected 
    # to the start page because your Apache does not expose the REDIRECT_STATUS 
    # environment variable, you have 2 choices: 
    # - disable this feature by commenting the following 2 lines or 
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the 
    # following RewriteCond (best solution) 
    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 

    # If the requested filename exists, simply serve it. 
    # We only want to let Apache serve files and not directories. 
    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 

    # Rewrite all other queries to the front controller. 
    RewriteRule .? %{ENV:BASE}/app.php [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
     # When mod_rewrite is not available, we instruct a temporary redirect of 
     # the start page to the front controller explicitly so that the website 
     # and the generated links can still be used. 
     RedirectMatch 302 ^/$ /app.php/ 
     # RedirectTemp cannot be used instead 
    </IfModule> 
</IfModule> 

Je ne comprends pas beacause forme de travail, mais pas de données avec le chrome client Rest.

mes données reçues avec la forme

Request {#8 ▼ 
    +attributes: ParameterBag {#11 ▶} 
    +request: ParameterBag {#9 ▼ 
    #parameters: array:3 [▶] 
    } 
    +query: ParameterBag {#10 ▶} 
    +server: ServerBag {#14 ▶} 
    +files: FileBag {#13 ▶} 
    +cookies: ParameterBag {#12 ▶} 
    +headers: HeaderBag {#15 ▶} 
    #content: null 
    #languages: null 
    #charsets: null 
    #encodings: null 
    #acceptableContentTypes: null 
    #pathInfo: "/api/v2/imports/initials.json" 
    #requestUri: "url" 
    #baseUrl: "url" 
    #basePath: null 
    #method: "POST" 
    #format: "xml" 
    #session: Session {#413 ▶} 
    #locale: null 
    #defaultLocale: "fr" 
    -isForwardedValid: true 

et demande de poste de repos

SyncTwoController.php on line 47: 
Request {#8 
    +attributes: ParameterBag {#11 
    #parameters: array:6 [ 
     "media_type" => "application/json" 
     "_controller" => "AppBundle\Controller\Rest\SyncTwoController::postImportInitialAction" 
     "_format" => "json" 
     "_route" => "post_import_initial" 
     "_route_params" => array:1 [ 
     "_format" => "json" 
     ] 
     "paramFetcher" => ParamFetcher {#441 
     -container: appDevDebugProjectContainer {#370 …12} 
     -parameterBag: ParameterBag {#443 
      -paramReader: ParamReader {#442 
      -annotationReader: CachedReader {#337 
       -delegate: AnnotationReader {#336 
       -parser: DocParser {#335 
        -lexer: DocLexer {#334 
        #noCase: array:9 [ 
         "@" => 101 
         "," => 104 
         "(" => 109 
         ")" => 103 
         "{" => 108 
         "}" => 102 
         "=" => 105 
         ":" => 112 
         "\" => 107 
        ] 
        #withCase: array:3 [ 
         "true" => 110 
         "false" => 106 
         "null" => 111 
        ] 
        -input: null 
        -tokens: [] 
        -position: 0 
        -peek: 0 
        +lookahead: null 
        +token: null 
        } 
        -target: null 
        -isNestedAnnotation: false 
        -imports: [] 
        -classExists: [] 
        -ignoreNotImportedAnnotations: false 
        -namespaces: [] 
        -ignoredAnnotationNames: [] 
        -ignoredAnnotationNamespaces: [] 
        -context: "" 
       } 
       -preParser: DocParser {#333 
        -lexer: DocLexer {#332 
        #noCase: array:9 [ 
         "@" => 101 
         "," => 104 
         "(" => 109 
         " 

Merci pour avoir aider.

Répondre

0

Je trouve une solution, les problèmes sont en-tête. Pour résoudre je dois former-données dans l'en-tête et pas x-www-form-urlencoded où est l'information ne peut pas obtenir avec $ _POST.