我刚才在PHP中卷曲......我只是想知道如何将这个curl命令转换为PHP:
curl https://ancient-test.chargebee.com/api/v1/portal_sessions \
-u test_rdsfgfgfddsffds: \
-d customer[id]="EXAMPLE" \
-d redirect_url="https://yourdomain.com/users/3490343"
现在我得到了:
$post_data['customer']['id'] = "EXAMPLE";
$post_data['redirect_url'] = "http://" . SITE_URL . "/myaccount/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://ancient-test.chargebee.com/api/v1/portal_sessions");
curl_setopt($ch,CURLOPT_USERPWD,"test_rdsfgfgfddsffds:");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
$output = curl_exec($ch);
curl_close($ch);
但我收到错误消息:
{"错误":[{"消息":"提交时出现错误"},{" param":&# 34;客户[id]","消息":"不能为空白"}]}
感谢您的帮助!
扬
答案 0 :(得分:-1)
在这里使用curl可能就是答案Posting with PHP and Curl, deep array
public class HelloVisionActivity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "Example::HelloVisionWorld::Activity";
private CameraBridgeViewBase mOpenCvCameraView;
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
return inputFrame.rgba();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_hello_vision);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloVisionView);
//Set the view as visible
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@Override
public void onResume() {
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_hello_vision, menu);
return true;
}
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@SuppressLint("LongLogTag")
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Guzzle是一个非常棒的HTTP客户端库,包含PHP中的curl,可以让您的生活更轻松:)
使用guzzle v6,您的PHP代码将如下所示:
$post_data['customer[id]'] = "EXAMPLE";
答案 1 :(得分:-1)
https://github.com/CircleOfNice/CiRestClientBundle
这个有一个美丽的api。
-(void) queryFeed {
self.feedArray = [NSMutableArray arrayWithArray:[self.event objectForKey:@"feedArray"]];
NSLog(@"feedArray is: %lu", (unsigned long)self.feedArray.count);
for (NSMutableDictionary *feedDictionary in self.feedArray) {
if ([feedDictionary objectForKey:@"text"] != nil) {
PFQuery *textQuery = [PFQuery queryWithClassName:@"EventTexts"];
[textQuery whereKey:@"objectId" equalTo:[feedDictionary objectForKey:@"text"]];
[textQuery includeKey:@"user"];
[textQuery findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error) {
if (result.count != 0) {
PFUser *textUser;
for (PFObject *textObject in result) {
textUser = textObject[@"user"];
}
PFObject *textObject = result[0];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:[textObject objectForKey:@"text"] forKey:@"text"];
[dictionary setObject:textObject.createdAt forKey:@"createdAt"];
[dictionary setObject:textUser forKey:@"user"];
[self.dictionaryArray insertObject:dictionary atIndex:0];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
self.sortedDictionaryArray = [[self.dictionaryArray sortedArrayUsingDescriptors:sortDescriptors]mutableCopy];
[self.tableView reloadData];
if (![self.usersDictionary objectForKey:textUser.objectId]) {
PFFile *photoFile = [textUser objectForKey:@"profilePicture"];
[photoFile getDataInBackgroundWithBlock:^(NSData *result, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:result];
[self.usersDictionary setObject:image forKey:textUser.objectId];
}
}];
} else {
}
[self.tableView reloadData];
}
}];
} else {
}
}
NSLog(@"dictArray count: %ld", self.dictionaryArray.count);
NSLog(@"feedArray count: %ld", self.feedArray.count);
[self.tableView reloadData];
}