我正在学习泽西岛,并从一个问题绊到另一个问题。我刚刚从Java客户端获得了服务(在得到某人的帮助之后)。服务类如下:
@Path("/user")
public class UserService extends AbstractService {
private static final NouLogger logger = NouLogger
.getLogger(UserService.class);
@Path("fbregister")
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String createNewFBUser(@FormParam("fbuserid") String userid,
@FormParam("fbmailid") String emailId,
@FormParam("fbfullname") String fullName,
@FormParam("fbusertoken") String userToken,
@Context HttpServletResponse servletResponse) throws IOException,
DatabaseException {
final String methodName = "createNewFBUser";
User user = new User();
user.setEmail(emailId);
user.setName(fullName);
user.setFacebookSecret(userToken);
Session session = null;
try {
session = getSession();
} catch (DatabaseException e) {
final String message = "Error occurred while fetching session.";
logger.error(methodName, message, e);
e.printStackTrace();
}
UserDAO userDAO = DAOFactory.DEFAULT.buildUserDAO();
Transaction txn = session.beginTransaction();
userDAO.save(user);
txn.commit();
closeSession();
return user.getId().toString();
}
}
当我从Java客户端调用它时,这很好用。但是当我从iOS代码中调用它时,我获得了所有参数的所有空值。 iOS代码如下:
// To encode parameter.
NSString *fb_userid = [user objectForKey:@"id"];
NSString *fb_mailid = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)[user objectForKey:@"email"], NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8 ));
NSString *fb_fullname = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)user.name, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8 ));
NSString *fbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
NSLog(@"user = %@", user);
NSLog(@"fb_userid = %@", fb_userid);
NSLog(@"fb_mailid = %@", fb_mailid);
NSLog(@"fb_fullname = %@", fb_fullname);
// To send url Request.
NSString *url1 =[NSString stringWithFormat:@"http://myip:8080/nou/rest/user/fbregister?fbuserid=%@&fbmailid=%@&fbfullname=%@&fbusertoken=%@", fb_userid, fb_mailid, fb_fullname, fbAccessToken];
NSURL *url = [NSURL URLWithString:url1];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
theConnection1 = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
知道为什么会这样吗?我把它放在远程调试上,我也可以看到正在调用的方法,我的数据库条目已经创建但是所有的空值都被放入其中。帮我解决这个问题。
修改
我尝试只发送一个参数'id',但它也没有用。
答案 0 :(得分:1)
在您的java代码中,您接受参数作为FormParam,但在发布时,您将从客户端代码发送它作为查询字符串的一部分。所以: