English 中文(简体)
只是在 Obj- C( Iphone/ Xcode) 中装入php( Iphone/ Xcode)
原标题:Just loading php in Obj-C(Iphone/Xcode)

我有一个程序, 当你按下按钮时, 它会加载一个php 页面。 我不需要从中获取任何字符串 。 我只需要请求该页面, 用户在按下此按钮时不会看到它 。 我不想使用 uiwebview, 因为他们占用了太多的资源 。

How can I load a php page without showing it to the user on the press of a button? (Preferable code that can be inserted into an IBAction).

Ps. 我用谷歌搜索了半个小时左右 所以我找不到我在这里要的东西

谢谢!

最佳回答

您真的不需要任何来自网页的数据, 您只需要装入它一次, 才能通知网络服务器用户做了什么事情 。 您可以简单地使用 :

NSString* urlString = @"http://blaablaa.com/hello.php";
NSURL *theURL = [NSURL URLWithString:urlString];
NSURLRequest *req = [NSURLRequest requestWithURL:theURL];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:req delegate:self];

如果您需要获得请求结果(成功/失败),请执行

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    // your stuff here
}

在你的班级。

问题回答

只需使用 string with contentsofURL: encoding: error:

NSError *error;
NSURL *url = [NSURL URLWithString:@"http://server.com/file.php"];
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:&error];




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签