-1

我需要在我正在做的服务器上发送 http 请求,然后我使用 AFNetworking 发送请求。我不知道我必须在参数中设置什么

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://supreme2.ru/wp-comments-post.php"]
                                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                       timeoutInterval:15.0];
    request.HTTPMethod = @"POST";
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    NSString* params = @"author=pavel&email=xxxdozorxxx@gmail.com&url=http://supreme2.ru/0335-elektronnyj-myach/#comments&comment=afafaffsafasf";
    request.HTTPBody = [params dataUsingEncoding:NSUTF8StringEncoding];
    AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id object){
    NSData *data = (NSData *)object;

} failure:^(AFHTTPRequestOperation *operation, NSError *err) {
    NSLog(@"error %@", err);
} ];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
    [queue addOperation:operation];

一切正常,但我没有从服务器回答,也许我没有正确设置参数?或者它可能是服务器不好的工作?下面是服务器的php代码

<?php
    if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
        die ('Please do not load this page directly. Thanks!');
        if (!empty($post->post_password)) { // if there's a password
            if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
                <p class="nocomments">input password to see this detail<p>
                <?php
                return;
            }
        }
        $oddcomment = 'alt';
?>

<div class="mainzag"><div class="contzag"><h4>Comments (<?php comments_number('0','1','%')?>)</h4></div></div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<?php else : ?>
<form action="http://supreme2.ru/wp-comments-post.php" method="post" id="commentform">
<?php if ( $user_ID ) : ?>
<?php else : ?>
            <div id="comsund">
                <div id="authbtn"><a href="https://loginza.ru/api/widget?token_url=<?php the_permalink() ?>&amp;providers_set=vkontakte,google,yandex,mailru,twitter,facebook" class="loginza authbtn1" rel="nofollow">Авторизация</a></div>
                <div id="comname"><input type="text" name="author" id="author"  onblur="if(this.value=='') this.value='Your name';" onfocus="if(this.value=='Ваше имя') this.value='';" value="Your name" maxlength="50" tabindex="1" /></div>
                <div id="commail"><input type="text" name="email" id="email"  onblur="if(this.value=='') this.value='Your E-mail';" onfocus="if(this.value=='Ваш E-mail') this.value='';" value="Your E-mail" maxlength="50" tabindex="2" /></div>
            </div>
<?php endif; ?>
            <div id="comms">
                <div id="combg"><textarea name="comment" id="comment" cols="" rows="" tabindex="4"></textarea></div>
                <div id="combtn"><input type="image" name="submit" value="submit" src="http://supreme2.ru/img/combtn.jpg" tabindex="5" /></div>
                <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
            </div>

<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; ?>
<?php if ( $user_ID ) : ?>
<div class="comexit"><a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Quit">Выйти</a></div>
<?php endif; ?>
    <?php foreach ($comments as $comment) : ?>
        <div class="comline"></div>
            <div class="compod" id="comment-<?php comment_ID() ?>">
                <div class="cominfo">
                    <div class="comman"><p><?php comment_author_link() ?><span>, <?php comment_date('j.m.Y') ?> (<?php comment_time() ?>)</span></p></div>
                    <div class="comtext"><?php if ($comment->comment_approved == '0') : ?><p style="color:#a6c232;font-style:italic;">Your comment in moderation</p><?php endif; ?><?php comment_text() ?></div>
                </div>
                <div class="comrate">
                <?php ckrating_display_karma();  ?>
                </div>
            </div>

    <?php endforeach; ?>
  <?php if ('open' == $post->comment_status) : ?> 
     <?php else : ?>
        <p class="nocomments">Comments are closed</p>
            <?php endif; ?>

<?php if ('open' == $post->comment_status) : ?>
<?php endif; ?>Your E-mail
4

1 回答 1

1

正如亚历克斯所说,你应该做一个

[operation start];

或一个

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];

在您的代码末尾(如果它不存在)

于 2012-06-20T20:21:30.613 回答